Skip to content

Commit 18914f7

Browse files
committed
fix
1 parent 1799fb4 commit 18914f7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Attribute/MutableCollection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public function replace($value, Model &$object, ?Path $path = null)
6262
// Act like the relation is already saved. This allows running validations, if needed.
6363
$object->setRelation($this->attribute, $existingObjects);
6464

65-
$object->saved(function (Model $model) use ($existingObjectIds) {
65+
$object->saved(function (Model $model) use ($object, $existingObjectIds) {
6666
// Save relationships only after the model is saved. Essential if the model is new.
67-
$model->{$this->attribute}()->sync($existingObjectIds->all());
67+
// Intentionlly `$object` is used instead of `$model`, to avoid accidentially updating the wrong model.
68+
$object->{$this->attribute}()->sync($existingObjectIds->all());
6869
});
6970

7071
}

0 commit comments

Comments
 (0)