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?
on 2006-01-03 20:37
on 2006-01-03 21:00
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 2006-01-03 21:06
On 1/3/06, Stephen Gerstacker <firstname.lastname@example.org> wrote: > -- > 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 email@example.com 1-866-263-3261
on 2006-01-03 21:38
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 > Matt I 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).