Closed cviebrock closed 8 years ago
Yeah I've thought about that also, and it'll be a good feature (same with average). It fits well with the behaviours idea and system of Eloquence, so I'm happy to include something like this.
If you have a chance, can you take a look at the PR #35 I submitted? It's not passing the tests ... but I think that's because I have something set up incorrectly in the tests, not in the actual implementation.
Thanks!
Will do @cviebrock - just been away on holidays (and currently sick).
Get well soon!
I'll be renaming the SumCache to TotalCache - I think it's a better name :) Thanks for this.
Your package, so your call. :) I was trying to keep parity with the underlying SQL commands normally associated with the actions:
COUNT()
--> CountCacheSUM()
--> SumCacheAVG()
--> AvgCache (..eventually)And thanks!
hehe, I ended up reverting it back to sum anyway - Summable works nicely as a trait ^_^
Rolls off the tongue better than Totalable. ;)
In the same way we can add count caching to a model, it would be nice to have a behaviour that cached the sum of some value.
As an example, a User has many Orders. Right now, we could add a
order_count
field to the User model and use the existing behaviour to update that. I'm suggesting something that allows one to add a anorder_total
field as well, that is a cached copy of the sum of some field on the Orders table for that User. e.g.Not sure how the configuration would look, but maybe something like this on the Order class: