http://wiki.rubyonrails.org/rails/pages/MagicFieldNames
see Counter Cache section as one of the solutions
On 3/20/06, Jong Hian Zin <mail.zin@gmail.com>
wrote:>
> What is the best way to get the running total of a number field in child
> records. Let say I have an Order model, which has_many :line_items, and
each
> LineItem has an amount field. I would like to get the grand total of a
> specific Order. Is it a good idea to add a ''total'' column
in the ''orders''
> table and update it every time a line_item is created/updated/deleted?
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060320/48b79375/attachment-0001.html