Is it possible to define a subclass for a model, that defines additional data columns, which are stored in a separate table? Is there any description, how to do this? -- 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 Thu, Aug 19, 2010 at 8:05 AM, Fritz Trapper <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Is it possible to define a subclass for a model, that defines additional > data columns, which are stored in a separate table?What you are describing is "Multiple Table Inheritance". I don''t think stock rails handles this. Rails supports "Single Table Inheritance"[1] in which you''ll store the union of all column types in the base table. [1] http://api.rubyonrails.org/classes/ActiveRecord/Base.html> Is there any description, how to do this?For STI make a table for the base class and subclass arbitrarily. -- med vänlig hälsning David JH -- 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.
David J. Hamilton wrote:> On Thu, Aug 19, 2010 at 8:05 AM, Fritz Trapper <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> Is it possible to define a subclass for a model, that defines additional >> data columns, which are stored in a separate table? > > What you are describing is "Multiple Table Inheritance". I don''t > think stock rails handles this. Rails supports "Single Table > Inheritance"[1] in which you''ll store the union of all column types in > the base table.But you could use has_one. Best, -- 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.
On 19 August 2010 16:05, Fritz Trapper <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Is it possible to define a subclass for a model, that defines additional > data columns, which are stored in a separate table? > > Is there any description, how to do this?You can certainly subclass a model. Then the subclass could have a :has_one relationship to another model with the extra columns which the superclass doesn''t have. If you want to make it transparent, you can delegate the calls for the extra tables in the associated model, so instead of: foo.bar.extra_value you can call: foo.extra_value -- 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.
Oh thanks. It seems, I not see wood for trees... -- 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.