Not sure how helpful my comments will be, but...

Sale = Order
Pop = LineItem
Product = Product

An Order has many LineItems.  A LineItem belongs to an Order.  A  
LineItem has one Product.

The LineItem model should have fields for quantity, discount, and the  
price of the product at the time the order was placed.

The Order model should only need to look at it's LineItems to  
determine the total price.

Don't know if that will help work your way through the issue or not...  
if not, ignore me :)

-philip

On May 27, 2009, at 3:29 PM, Bruno Sousa wrote:

>
> Hi,
> I couldn't find a better word for pop, but let's go:
> There are 3 models: sale, pop and product
>
> sale:
>  -total:integer
> pop:
>  -quantity:integer
>  -discount:float
> product:
>  -name:string
>  -price:float
>
> A sale can have many different products, each one has a quantity and
> discount associated.
> So each sale has_many :products through => pops
> And each product has_many :sales through => pops
>
> For example:
> +-------------------------------------------+
> |--> Sale 1   <--> Pop 1     <--> Product 1 |
> |                  qty = 20                 |
> |                  disc= 0.1                |
> |             <--> Pop 2     <--> Product 2 |
> |                  qty = 10                 |
> |                  disc=0                   |
> +-------------------------------------------+
> |--> Sale 2   <--> Pop 3     <--> Product 3 |
> |                  qty = 4                  |
> |                  disc= 0.5                |
> |             <--> Pop 4     <--> Product 1 |
> |                  qty = 5                  |
> |                  disc=0                   |
> +-------------------------------------------+
>
> By the time I associate a sale with a product I need to especify
> quantity and discount because Sale's model has validations that uses
> quantity and discount values.
>
> In rails console:
> s = Sale.new
> p = Product.new
> p.save
> s.products << Product.last
> s.save
>
> This way I can't use pops columns before saving the sale. How can I do
> that?
> -- 
> Posted via http://www.ruby-forum.com/.
>
> >


--~--~---------~--~----~------------~-------~--~----~
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