Sale, pop and product

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:

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 :slight_smile:

-philip

Thanks for your help!

I got this code:
1. s = Sale.new
2. p = Product.new
3. p.save
pop = s.pops.build(:qty => 10, :disc = 0) #associates pop with sale and
puts it in the collection
4. pop.product = p
5. s.save #saves sale and pop

Just found out that "pops" callbacks simply do not work.
for example:
class Sale
  has_many :pops, :dependent => :destroy
end

class Pop
  before_destroy :do_something
end

if I destroy a sale that has a pop associated, before_destroy from Pop
is not called.

why that happens?

Any ideas how can this be used in new/create views?

Bruno Sousa wrote: