rails/activerecord/test/models/invoice.rb
2010-01-08 21:45:02 +01:00

5 lines
160 B
Ruby

class Invoice < ActiveRecord::Base
has_many :line_items, :autosave => true
before_save {|record| record.balance = record.line_items.map(&:amount).sum }
end