Hi all, I am trying to understand which is the best way to save aggregate values if you also want to sort using them. Right now, I have a customer object with inside an array of deals.... The deals have 3 statuses (lost, won, pipeline) and a monetary value. What I would like to do is to create 3 sums (one per status) and use them in the customer...
What is the best way to go?
- Virtual (but I guess i cannot sort by it then which is bad)
- Add a hook for the customer object pre save (and recalculate the sums whenever the customer object is updated).
- A better way?
On top of if, shall i use $aggregate and how?
thanks a lot