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

saveField does not work on AggregateCacheBehavior models #5

Closed cwbit closed 10 years ago

cwbit commented 10 years ago

saveField passes a limited number of fields to the afterSave methods which means AggregateCacheBehavior cannot properly update related models as it is not guaranteed to have all the keys it needs.

To fix this code was added to AggregateCacheBehavior::afterSave to check the current $model->data against $model->schema to make sure all the fields were available.

However, AggregateCacheBehavior::afterSave is doing array_diff_key in the wrong order - it needs to compare the current data array against the full schema to make sure all the fields are in there. It is currently comparing the schema against the current data array - which wrongly gives the current data array priority over schema, thus rendering the fix useless.

AggregateCacheBehavior::afterSave needs to be modified to compare $model->data against $model->schema (reverse current order).