Skip to content

Commit 05f746a

Browse files
committed
fix: HasMany - hookResults param is ignored
1 parent 02eebb6 commit 05f746a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/Relationships/HasManyRelationship.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ public function query(bool $hookResults = true): ModelQuery
5858
$query = $this->referenceModel::query()
5959
->where("{$this->foreignKeyColumn} = ?", $pkVal);
6060

61-
$query->addResultHook(function (Model $model) {
62-
$pkVal = $model->getPrimaryKeyValue();
63-
$this->loadedModels[$pkVal] = $model;
64-
});
61+
if ($hookResults) {
62+
$query->addResultHook(function (Model $model) {
63+
$pkVal = $model->getPrimaryKeyValue();
64+
$this->loadedModels[$pkVal] = $model;
65+
});
66+
}
6567

6668
return $query;
6769
}

0 commit comments

Comments
 (0)