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?

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 G. [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
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 M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261

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).