OK, I worked out how to do this. Here''s the answer to my own question:
> An order can hold multiple line items. Each line item is for a
> certain number of any given product. There are four products, each
> in a different table because they have completely different
> attributes. So I have:
>
> Order
> - has many LineItems
>
> LineItem
> - belongs to an Order
> - holds the quantity of the particular product
> - has one {ProductA or ProductB or ProductC or ProductD}
>
> ProductA
> - belongs to many LineItems
> - holds various attributes unique to product A
>
> ProductB
> - belongs to many LineItems
> - holds various attributes unique to product B
>
> ...etc for ProductC and ProductB
>
> How do I set up LineItem so it is polymorphic with respect to the
> product it has?
LineItem
- belongs_to :orderable, ;polymorphic => true
- column :orderable_id, :integer
- column :orderable_type, :string
ProductA
- has_one :line_item, :as => orderable
ProductB, ProductC, ProductD
- as for ProductA
Regards,
Andy Stewart
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---