Browse Source

only update count if valid count is given

Callback might refuse the count update
Johannes Jordan 8 years ago
parent
commit
3ce664504e
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/ORM/Behavior/CounterCacheBehavior.php

+ 8 - 3
src/ORM/Behavior/CounterCacheBehavior.php

@@ -238,8 +238,10 @@ class CounterCacheBehavior extends Behavior
             } else {
                 $count = $this->_getCount($config, $countConditions);
             }
-
-            $assoc->getTarget()->updateAll([$field => $count], $updateConditions);
+            if (!is_null($count)) {
+                $assoc->getTarget()->updateAll([$field => $count],
+                    $updateConditions);
+            }
 
             if (isset($updateOriginalConditions)) {
                 if (is_callable($config)) {
@@ -250,7 +252,10 @@ class CounterCacheBehavior extends Behavior
                 } else {
                     $count = $this->_getCount($config, $countOriginalConditions);
                 }
-                $assoc->getTarget()->updateAll([$field => $count], $updateOriginalConditions);
+                if (!is_null($count)) {
+                    $assoc->getTarget()->updateAll([$field => $count],
+                        $updateOriginalConditions);
+                }
             }
         }
     }