Stephen Gerstacker
2006-Jan-03 19:37 UTC
[Rails] What''s the best way to do complex inheritance?
I have a Merchant class that has many Products. Product is an abstract class which has many subclasses (ProductA, ProductB, etc). All Products have common data, like ''name'', ''status'', ''created_on'', etc... but they also have some completely different properties. It seems like Active Record only supports Single Table Inheritance. This would make my Products'' table _huge_ and mostly empty. Is there a way around this or am I stuck with a sloppy table? Would I be better of just having seperate lists for each Product that the merchant has? -- Posted via http://www.ruby-forum.com/.
Stephen, Single Table Inheritance will work in this case if you pull out the extraneous attributes and put them in auxillary tables. Then you can associate the appropriate attiribute tables to subclasses of Product as needed. JM2C Matt On 1/3/06, Stephen Gerstacker <stephen@shortround.net> wrote:> > I have a Merchant class that has many Products. Product is an abstract > class which has many subclasses (ProductA, ProductB, etc). All Products > have common data, like ''name'', ''status'', ''created_on'', etc... but they > also have some completely different properties. > > It seems like Active Record only supports Single Table Inheritance. > This would make my Products'' table _huge_ and mostly empty. Is there a > way around this or am I stuck with a sloppy table? Would I be better of > just having seperate lists for each Product that the merchant has? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20060103/2d337986/attachment-0001.html
Kyle Maxwell
2006-Jan-03 20:06 UTC
[Rails] What''s the best way to do complex inheritance?
On 1/3/06, Stephen Gerstacker <stephen@shortround.net> wrote:> I have a Merchant class that has many Products. Product is an abstract > class which has many subclasses (ProductA, ProductB, etc). All Products > have common data, like ''name'', ''status'', ''created_on'', etc... but they > also have some completely different properties. > > It seems like Active Record only supports Single Table Inheritance. > This would make my Products'' table _huge_ and mostly empty. Is there a > way around this or am I stuck with a sloppy table? Would I be better of > just having seperate lists for each Product that the merchant has? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Product.has_many :attributes create_table(:attributes) do |t| t.column :key, :string t.column :value, :text end -- Kyle Maxwell Chief Technologist E Factor Media // FN Interactive kyle@efactormedia.com 1-866-263-3261
Stephen Gerstacker
2006-Jan-03 20:39 UTC
[Rails] Re: What''s the best way to do complex inheritance?
Matt Goss wrote:> Stephen, > Single Table Inheritance will work in this case if you pull out the > extraneous attributes and put them in auxillary tables. Then you can > associate the appropriate attiribute tables to subclasses of Product as > needed. > JM2C > MattI tried something like this. I made a ProductAData and made it belong to ProductA. I then created a view so that I could create a new ProductA with its ProductAData along with it. If the ProductA fields are valid, but the ProductAData isn''t, the new ProductA is saved to the database without the ProductAData. What''s the proper way to do this? BTW, I''m a little green with this stuff (if it wasn''t obvious). -- Posted via http://www.ruby-forum.com/.