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. -- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/f18259af/attachment.html
Moreover, why can''t I do a Deal.find or a Product.find ??? On 5/4/06, subimage interactive <subimage@gmail.com> wrote:> > 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. > > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ >-- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/b328cd28/attachment.html
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. subimage interactive wrote:> Moreover, why can''t I do a Deal.find or a Product.find ??? > > On 5/4/06, *subimage interactive* <subimage@gmail.com > <mailto:subimage@gmail.com> > wrote: > > 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. > > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ > > > > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/76dc56a8/attachment.html
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 5/5/06, Chris T <ctmailinglists@googlemail.com> wrote:> > 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. > > subimage interactive wrote: > > Moreover, why can''t I do a Deal.find or a Product.find ??? > > On 5/4/06, subimage interactive <subimage@gmail.com > wrote: > > > > 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. > > > > > > -- > > seth at subimage interactive > > http://www.subimage.com/sublog/ > > > > > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ > > ------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.orghttp://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/defff057/attachment.html
I''m an idiot - I had Product still subclassing ActiveRecord, not Item... THanks :) On 5/5/06, subimage interactive <subimage@gmail.com> wrote:> > 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 5/5/06, Chris T <ctmailinglists@googlemail.com> wrote: > > > > 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. > > > > subimage interactive wrote: > > > > Moreover, why can''t I do a Deal.find or a Product.find ??? > > > > On 5/4/06, subimage interactive <subimage@gmail.com > wrote: > > > > > > 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. > > > > > > > > > -- > > > seth at subimage interactive > > > http://www.subimage.com/sublog/ > > > > > > > > > > > -- > > seth at subimage interactive > > http://www.subimage.com/sublog/ > > > > ------------------------------ > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ >-- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/9c6063c9/attachment.html