Hey gang, How does STI work with HABTM? For instance...let's say I have the following models ----- Category < ActiveRecord::Base Item < ActiveRecord::Base Product < Item Deal < Item ----- Each product or deal can have categories. Would I then setup Item with has_and_belongs_to_many :categories, then create a table categories_items ??? Is there a better way to do it? Haven't done this with STI yet - Thanks.
on 2006-05-05 08:34
on 2006-05-05 09:04
Moreover, why can't I do a Deal.find or a Product.find ???
on 2006-05-05 11:45
You should be able to do a Deal.find. I have a very similar setup and have no prob. Wondering if it's finding the subclass declarations. Are the subclasses in the same file: item.rb or in their own ones? Yes, you'd have the has_and_belongs_to_many :categories declaration in the item setup, and the subclasses would inherit the relationship.
on 2006-05-05 11:57
They are all in their own separate files - do they need to be all in one file??? If I try Product.find or Deal.find from script/console I get a SQL error telling me the table products or deals doesn't exist.
on 2006-05-05 21:22
I'm an idiot - I had Product still subclassing ActiveRecord, not Item... THanks :)