Skip to content

Commit

Permalink
Fix avoid recursive reference in relation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Jun 5, 2024
1 parent 432ad29 commit 0a455b1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Models/Behaviors/HasRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function loadRelated(string $browserName): Collection
/** @var \A17\Twill\Models\Model $model */
if ($model = $item->related) {
$model->setRelation('pivot', $item);
$item->unsetRelation('related');

return $model;
}
Expand Down Expand Up @@ -79,7 +80,7 @@ public function saveRelated(array|Collection $items, string $browserName): void
}

$firstMatchKey = $itemsToProcess
->where(fn ($item) => $item->related_id === $id && $item->related_type === $type)
->where(fn (RelatedItem $item) => $item->related_id == $id && $item->related_type === $type)
// We should only have one item always as you cannot select the same items twice.
->keys()
->first();
Expand Down

0 comments on commit 0a455b1

Please sign in to comment.