3 tables. item, brand, commercial item -------- id name brand_id name brand --------- id name commercial ---------- id item_id The idea is that a commercial will have one item. each item will have brand. and a brand may have zero to many items. I can''t figure out how to make the relationships for my models. Eventually, i''d like to be able to show a brand name from a commercial''s view. --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MichaelLatta
2007-May-30 21:17 UTC
Re: newb trying to figure out ActiveRecord relationships
Item --------- belongs_to :brand has_one :commercial Brand ---------- has_many :items Commercial ---------- belongs_to :item Michael On May 30, 1:18 pm, tayknight <taykni...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 3 tables. item, brand, commercial > > item > -------- > id > name > brand_id > name > > brand > --------- > id > name > > commercial > ---------- > id > item_id > > The idea is that a commercial will have one item. > each item will have brand. > and a brand may have zero to many items. > > I can''t figure out how to make the relationships for my models. > Eventually, i''d like to be able to show a brand name from a > commercial''s view.--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Michael. That worked perfectly. For some reason I had all the relationships exactly backwards. On May 30, 4:17 pm, MichaelLatta <lat...-ee4meeAH724@public.gmane.org> wrote:> Item > --------- > belongs_to :brand > has_one :commercial > > Brand > ---------- > has_many :items > > Commercial > ---------- > belongs_to :item > > Michael > > On May 30, 1:18 pm, tayknight <taykni...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 3 tables. item, brand, commercial > > > item > > -------- > > id > > name > > brand_id > > name > > > brand > > --------- > > id > > name > > > commercial > > ---------- > > id > > item_id > > > The idea is that a commercial will have one item. > > each item will have brand. > > and a brand may have zero to many items. > > > I can''t figure out how to make the relationships for my models. > > Eventually, i''d like to be able to show a brand name from a > > commercial''s view.--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---