Skip to content

Commit

Permalink
handle when the relation is null. e.g: when we set null to a relation…
Browse files Browse the repository at this point in the history
… key
  • Loading branch information
fmarquesto committed May 15, 2024
1 parent c0c9e29 commit 1af0c02
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Behaviours/CountCache/CountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public function update(): void
$originalRelatedModel = $config->emptyRelatedModel($this->model)->find($this->model->getOriginal($foreignKey));

$this->updateCacheValue($originalRelatedModel, $config, -1);
$this->updateCacheValue($config->relatedModel($this->model), $config, 1);

// if the relation is null, then we don't need to do anything else.
if($this->model->{$foreignKey}) {
$this->updateCacheValue($config->relatedModel($this->model), $config, 1);
}
});
}

Expand Down

0 comments on commit 1af0c02

Please sign in to comment.