I''ve done some reading on Single Table Inheritance. I think I need something a little more though. Classic example. class Animal < ActiveRecord::Base // db fields: name: string age: int type: string breed: string end class Feline < Animal // db fields: whisker_count: int end class Canine < Animal // db fields: seeing_eye_dog: boolean end So how do Canine and Feline inherit the fields from Animal although they don''t require each others fields. Does the Animals table just contain all the fields but value can be null and only returns the available fields for that Model? Cheers, -- 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.
yes, the Animal contains all the field and if you create a Feline instance as feline, seeing_eye_dog will be left empty. On Tue, Mar 30, 2010 at 3:19 PM, brianp <brian.o.pearce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve done some reading on Single Table Inheritance. > > I think I need something a little more though. > > Classic example. > > class Animal < ActiveRecord::Base > // db fields: > name: string > age: int > type: string > breed: string > end > > class Feline < Animal > // db fields: > whisker_count: int > end > > class Canine < Animal > // db fields: > seeing_eye_dog: boolean > end > > So how do Canine and Feline inherit the fields from Animal although > they don''t require each others fields. Does the Animals table just > contain all the fields but value can be null and only returns the > available fields for that Model? > > Cheers, > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Hmmm.... This could lead to 60+ blank fields a record (for that table). Is that bad design, is there a better method I should explore? Or is this just normal and I should go with it? On Mar 30, 12:23 am, Yong Gu <zerogy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yes, the Animal contains all the field and if you create a Feline instance > as feline, seeing_eye_dog will be left empty. > > On Tue, Mar 30, 2010 at 3:19 PM, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''ve done some reading on Single Table Inheritance. > > > I think I need something a little more though. > > > Classic example. > > > class Animal < ActiveRecord::Base > > // db fields: > > name: string > > age: int > > type: string > > breed: string > > end > > > class Feline < Animal > > // db fields: > > whisker_count: int > > end > > > class Canine < Animal > > // db fields: > > seeing_eye_dog: boolean > > end > > > So how do Canine and Feline inherit the fields from Animal although > > they don''t require each others fields. Does the Animals table just > > contain all the fields but value can be null and only returns the > > available fields for that Model? > > > Cheers, > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
I am sorry that i do not have too much ideas about whether STI(Single Table Inheritance) are good or not, it depends. here is article(not mine) you could refer: http://code.alexreisner.com/articles/single-table-inheritance-in-rails.html I hope that could help you On Tue, Mar 30, 2010 at 3:30 PM, brianp <brian.o.pearce-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmmm.... This could lead to 60+ blank fields a record (for that > table). Is that bad design, is there a better method I should explore? > Or is this just normal and I should go with it? > > On Mar 30, 12:23 am, Yong Gu <zerogy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > yes, the Animal contains all the field and if you create a Feline > instance > > as feline, seeing_eye_dog will be left empty. > > > > On Tue, Mar 30, 2010 at 3:19 PM, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > I''ve done some reading on Single Table Inheritance. > > > > > I think I need something a little more though. > > > > > Classic example. > > > > > class Animal < ActiveRecord::Base > > > // db fields: > > > name: string > > > age: int > > > type: string > > > breed: string > > > end > > > > > class Feline < Animal > > > // db fields: > > > whisker_count: int > > > end > > > > > class Canine < Animal > > > // db fields: > > > seeing_eye_dog: boolean > > > end > > > > > So how do Canine and Feline inherit the fields from Animal although > > > they don''t require each others fields. Does the Animals table just > > > contain all the fields but value can be null and only returns the > > > available fields for that Model? > > > > > Cheers, > > > > > -- > > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Thanks for your replies Yong Gu. I believe the article was exactly the information I was seeking. Cheers, brianp On Mar 30, 12:39 am, Yong Gu <zerogy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am sorry that i do not have too much ideas about whether STI(Single Table > Inheritance) are good or not, it depends. > > here is article(not mine) you could refer: > > http://code.alexreisner.com/articles/single-table-inheritance-in-rail... > > I hope that could help you > > On Tue, Mar 30, 2010 at 3:30 PM, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hmmm.... This could lead to 60+ blank fields a record (for that > > table). Is that bad design, is there a better method I should explore? > > Or is this just normal and I should go with it? > > > On Mar 30, 12:23 am, Yong Gu <zerogy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > yes, the Animal contains all the field and if you create a Feline > > instance > > > as feline, seeing_eye_dog will be left empty. > > > > On Tue, Mar 30, 2010 at 3:19 PM, brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > I''ve done some reading on Single Table Inheritance. > > > > > I think I need something a little more though. > > > > > Classic example. > > > > > class Animal < ActiveRecord::Base > > > > // db fields: > > > > name: string > > > > age: int > > > > type: string > > > > breed: string > > > > end > > > > > class Feline < Animal > > > > // db fields: > > > > whisker_count: int > > > > end > > > > > class Canine < Animal > > > > // db fields: > > > > seeing_eye_dog: boolean > > > > end > > > > > So how do Canine and Feline inherit the fields from Animal although > > > > they don''t require each others fields. Does the Animals table just > > > > contain all the fields but value can be null and only returns the > > > > available fields for that Model? > > > > > Cheers, > > > > > -- > > > > 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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.