Let’s say we’ve got some calculated field in our find() method, something like SUM() or COUNT() or maybe AVG().
For the sake of example let’s do something simplistic, like:
This is all fine and well, except our total_count field does not appear with the rest of the fields in the resulting data array, but rather in it’s own index, like here:
We can use Set::check() and easily reformat our array in afterFind(), so that we can reference all fields in a consistent manner.
Try something like this in your model (or app model):
Now all fields appear where we would expect them.
Referencing all fields in a consistent manner (in the view, for example) is already a good enough benefit to use an approach similar to this one, but in addition if the change is ever made to the core in order to fix this up, your code will not be affected in any way.