The term you're looking for is LineItem, and it is typical to include things
like Peter suggests above -- snapshot information of any Product info that
would be necessary for printing invoices -- as well as tax calculations,
fulfillment status, return status, etc.  In this case, you would probably
want the following relationships:

Product has many LineItems / LineItem belongs to Product
Order has many LineItems / LineItem belongs to Order
Order has many Products through LineItems
Product has many Orders through LineItems

HTH...

On Tue, Jul 26, 2011 at 10:01 PM, Peter Bell <[email protected]> wrote:

> On Jul 26, 2011, at 3:58 PM, KlausG wrote:
>
> > I whonder why a product should have many orders? It belongs to
> > orders..
>
> Not being paying much attention to this thread, but whenever I see comments
> like this I'm cautious. Bear in mind that if products are mutable (can vary
> over time), typically you want to replicate some of their data as of a point
> in time so that a order has-many order_items which contain product
> information as at that point in time.
>
> Otherwise if you're not careful, updating the price on your products
> completely changes the value of all of your historic orders containing that
> product.
>
> Apologies if it's not relevant to the thread, but if it is, it's something
> that should be considered in the design.
>
> Best Wishes,
> Peter
>
> >
> >>> class Customer < ActiveRecord::Base
> >>>    has_many :orders
> >>> end
> >>> class Order < ActiveRecord::Base
> >>>    belongs_to :customer
> >>>    has_many :products
> >>> end
> >>> class Product < ActiveRecord::Base
> >>>    belongs_to :orders
> >>> end
> >
> > --
> > 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 [email protected].
> > To unsubscribe from this group, send email to
> [email protected].
> > For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> >
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to