2 tables Items and Categories
Categories (id, name) Items (id, name, category_id)
Category_id can be null, and there are Categories that has not an Item.
2 tables Items and Categories
Categories (id, name) Items (id, name, category_id)
Category_id can be null, and there are Categories that has not an Item.
Any chance of taking this list moderated?
2 tables Items and Categories
Categories (id, name) Items (id, name, category_id)
Category_id can be null, and there are Categories that has not an Item.
Well you may not realise it yet, but the fact that having a category_id on the items table and no other columns on the categories table works for you means that you have already solved this problem: the belongs_to always lives on the table with the foreign key and the has_many or has_one on the other side.
Fred
> 2 tables Items and Categories
> Categories (id, name) > Items (id, name, category_id)
> Category_id can be null, and there are Categories that has not an Item.
Well you may not realise it yet, but the fact that having a category_id on the items table and no other columns on the categories table works for you means that you have already solved this problem: the belongs_to always lives on the table with the foreign key and the has_many or has_one on the other side.
Oops, forgot to add that ActiveRecord::Associations::ClassMethods and rails.info cover this sort of stuff.
Fred