Skip to content

Commit

Permalink
fix: HasMany - hookResults param is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
roydejong committed Jan 20, 2024
1 parent 02eebb6 commit 05f746a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/Relationships/HasManyRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public function query(bool $hookResults = true): ModelQuery
$query = $this->referenceModel::query()
->where("{$this->foreignKeyColumn} = ?", $pkVal);

$query->addResultHook(function (Model $model) {
$pkVal = $model->getPrimaryKeyValue();
$this->loadedModels[$pkVal] = $model;
});
if ($hookResults) {
$query->addResultHook(function (Model $model) {
$pkVal = $model->getPrimaryKeyValue();
$this->loadedModels[$pkVal] = $model;
});
}

return $query;
}
Expand Down

0 comments on commit 05f746a

Please sign in to comment.