I have a class which contains two integers (a and b) and a reference to an entity.
I want to be able to report back on the sum of all the a's and b's within the class.
E.g. I might have three records:
Entity 1 2 3
a 5 9 3
b 8 1 2
I want my consolidated result for a to be 17, and for b 11.
I'm interested in view on the best approach to this. Now I could sum everything on the fly, but if there are lots of records that might be slow.
Or I could maintain a fake entity which contains the consolidated result and is updated each time any of the other objects are update.
Or I could have a different class for consolidated date?
All thoughts appreciated.
Thanks Chris
I think you need a class method, something like:
If you want it cached, you could have a class variable called
@@cache_invalidfor example, and set this to true any timeaorbchange. Then you could check this, and return a cached value if false, and run the code above if true (I've now edited the code to include this change).