Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arietimmerman committed Dec 11, 2024
1 parent 1799fb4 commit 18914f7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Attribute/MutableCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public function replace($value, Model &$object, ?Path $path = null)
// Act like the relation is already saved. This allows running validations, if needed.
$object->setRelation($this->attribute, $existingObjects);

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

}
Expand Down

0 comments on commit 18914f7

Please sign in to comment.