Hi Jas,

I just had the same situation and I created a model behavior where the
sum of all fields can be written to a parent model field afterSave()
and afterDelete(). The definition of the field and the scope of the
sum operation I define inside the model's belongsTo-Associaton.

If you just need this functionality on one model you can also
implement the functions directly in your model.

To recalculate the sum on each operation is just the easy way, if you
also want fast save and fast delete, you have to further implement an
update of the sum field that adds new values and subtracts deleted
values.

Regards,
Michael

Jas schrieb:
> If I have a table with a price field and these prices change very
> frequently, also rows are added and subtracted frequently.
> I need to make an element that shows the total of all these prices,
> what is the most efficient way to minimise load on the database.
> Keep in mind there might be anywhere between 2,000 and 500,000 rows.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to