I am not sure if I shall use single table inheritance, or something else. I have a model called horses, in that I have the columns mother_id and father_id where I of course intend to store the id of that horses mother and father. By that information alone I want to create a relation in the horses model for any horse to its mother and father. I wish to write something like @horse.mother.name I can''t understand what to do with the type column in this case. This should really be quite simple I guess. Would appreciate some help. Thanks -- 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.
2009/12/17 jeb <jonas-sgoA4MbTzF0@public.gmane.org>:> I am not sure if I shall use single table inheritance, or something > else. > > I have a model called horses, in that I have the columns mother_id and > father_id where I of course intend to store the id of that horses > mother and father. By that information alone I want to create a > relation in the horses model for any horse to its mother and father. I > wish to write something like @horse.mother.name > > I can''t understand what to do with the type column in this case. This > should really be quite simple I guess.Have a look at the guide on ActiveRecord Associations at http://guides.rubyonrails.org/ and the magic of Rails will become clear. Also, if you have not already done so work through the Getting Started guide. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 18, 7:18 am, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote:> I am not sure if I shall use single table inheritance, or something > else. > > I have a model called horses, in that I have the columns mother_id and > father_id where I of course intend to store the id of that horses > mother and father. By that information alone I want to create a > relation in the horses model for any horse to its mother and father. I > wish to write something like @horse.mother.name > > I can''t understand what to do with the type column in this case. This > should really be quite simple I guess. > > Would appreciate some help. > > ThanksThis is the problem that the relational database model was designed to solve in the first place. I would recommend learning the basics of database management if you don''t yet have any background. Single-table inheritance is a relatively new approach that developed out of object- relational mapping. Activerecord is magic when it comes to working with relations. I would highly recommend Eldon Alameda''s book "Foundation Rails 2." -- 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 just wrote a 3-part article on Rails STI here: http://joemcglynn.wordpress.com -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of adrianb Sent: Friday, December 18, 2009 8:48 PM To: Ruby on Rails: Talk Subject: [Rails] Re: single table relation, newbee question On Dec 18, 7:18 am, jeb <jo...-sgoA4MbTzF0@public.gmane.org> wrote:> I am not sure if I shall use single table inheritance, or something > else. > > I have a model called horses, in that I have the columns mother_id and > father_id where I of course intend to store the id of that horses > mother and father. By that information alone I want to create a > relation in the horses model for any horse to its mother and father. I > wish to write something like @horse.mother.name > > I can''t understand what to do with the type column in this case. This > should really be quite simple I guess. > > Would appreciate some help. > > ThanksThis is the problem that the relational database model was designed to solve in the first place. I would recommend learning the basics of database management if you don''t yet have any background. Single-table inheritance is a relatively new approach that developed out of object- relational mapping. Activerecord is magic when it comes to working with relations. I would highly recommend Eldon Alameda''s book "Foundation Rails 2." -- 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. -- 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.