I am trying to write a system with tables for engineers and system users. Both are people. It would seem that: class Person < ActiveRecord::Base belongs_to :job, :polymorphic => true end class Engineer < ActiveRecord::Base has_one :person, :as => :job end class SystemUser < ActiveRecord::Base has_one :person, :as => :job end would be a way of doing that provided that the two groups did not overlap (which of course they do). I am not at all keen to have engineer and system user attributes in the person table. I am sure there is a very simple solution to this but so far research has come up with overly complicated answers. Can anyone point me in the right direction? Thanks in advance Henry -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Henry Oss wrote:> I am trying to write a system with tables for engineers and system > users. Both are people. It would seem that: > > class Person < ActiveRecord::Base > belongs_to :job, :polymorphic => true > end > > class Engineer < ActiveRecord::Base > has_one :person, :as => :job > end > > class SystemUser < ActiveRecord::Base > has_one :person, :as => :job > endWaiiiit...engineers and system users are *jobs*? That''s what your associations would seem to say, unless I''m misreading.> > would be a way of doing that provided that the two groups did not > overlap (which of course they do). I am not at all keen to have > engineer and system user attributes in the person table.Do engineers and system users require different sets of fields in their respective tables? If not, you could just unify them as a single Person class with a role field.> > I am sure there is a very simple solution to this but so far research > has come up with overly complicated answers. Can anyone point me in the > right direction? > > Thanks in advance > > HenryBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Thanks for the reply.> > Waiiiit...engineers and system users are *jobs*? That''s what your > associations would seem to say, unless I''m misreading.Yes. Though perhaps role is a better choice of word.> > Do engineers and system users require different sets of fields in their > respective tables?Yes. So many that I don''t want to have redundant fields in a single table Henry -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 July 2010 08:50, Henry Oss <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Marnen > > Thanks for the reply. > >> >> Waiiiit...engineers and system users are *jobs*? That''s what your >> associations would seem to say, unless I''m misreading. > > Yes. Though perhaps role is a better choice of word. > >> >> Do engineers and system users require different sets of fields in their >> respective tables? > Yes. So many that I don''t want to have redundant fields in a single > tableWhy? The simplest solution is usually the best. How many million users will you have if disc space is your worry? You might want to look at STI if you want to keep the types functionally distinct, though again the simplicity of an all in one table with a role is usually preferable. You will easily find a plugin that will handle roles for you to make life even easier. The less code you write the fewer bugs you will have and the easier it will be to code, test and maintain. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Thanks for your reply. Colin Law wrote:>> So many that I don''t want to have redundant fields in a single >> table > > Why?Because I oversimplified and there are actually many roles, each with many attributes. As I understand it STI _is_ an all in one table with a role (conventionally "type"). Is the real answer that rails doesn''t adapt well to what I want to do? I can''t believe that. By the way I have found the has_many_polymorphs plugin but it seems like a sledgehammer to crack a very small nut. Henry -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.