cwbit / cakephp-aggregate-cache

A Behavior plugin for CakePHP that extends the idea of counterCache and counterScope to more fields
8 stars 4 forks source link

Fix notice when deleting last record #1

Closed Ali1 closed 10 years ago

Ali1 commented 10 years ago

When deleting the last record for a given foreign key, the $results (sum in my example) would be completely empty as there were no records to sum.

Ali1 commented 10 years ago

Notice (8): Undefined offset: 0 [APP/Model/Behavior/AggregateCacheBehavior.php, line 93]

Ali1 commented 10 years ago

Hello?

cwbit commented 10 years ago

Sorry I had other changes I wanted to merge and got pulled in too many directions.

I think it would be better to let each have a configurable default value instead of forcing ZERO if no values come back. Imagine that if I was trying to track the AVG of something - I would rather have it come back as NULL if no records exist than to set it as 0 which might imply records exist but just happen to average out to 0 (which might not always be the case).

I will merge this pull request for now because it provides a suitable, if not always ideal, solution. If someone wants to implement the configurable defaults for each function then I'll merge that, too.

Ali1 commented 10 years ago

:+1: agree