Newb trying to figure out ActiveRecord relationships


#1

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.


#2

Item

belongs_to :brand
has_one :commercial

Brand

has_many :items

Commercial

belongs_to :item

Michael


#3

Thanks, Michael. That worked perfectly. For some reason I had all the
relationships exactly backwards.