scaffold Book name price:integer
scaffold Sale book:referenes quantity:integer
Book.rb
has_many :sales
Sale.rb:
belongs_to :book
def total
book.price * quantity.to_f
end
问题:如果我要改价格它会重新计算所有过去的销售额。
我可以避免这种情况吗?通过某种方式保存产品的定价历史或具有current_price(活跃价格)?
听起来像一本书可以有很多价格,对不对? – Anthony
你自己回答。您需要在销售时存储sale_price或book_price。 –