Skip to content

Commit b294d2e

Browse files
Rely on model's isDirty() over getState()
The `getState()->is('dirty')` method only updates when changes are made to the owning model directly, and does not recognize changes made on ancestor embedded models. The `isDirty()` check, however, does not have this problem because it actively introspects ancestor embeds via `hasOneEmbeds->areDirty()` and `hasManyEmbeds->areDirty()`. As such, the `Store` needs to use this method when determining when to update the model, otherwise changes to ancestor embeds may not be committed.
1 parent ab7c1a6 commit b294d2e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Store/Store.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public function commit(Model $model)
503503
// Deletes must execute before updates to prevent an update then a delete.
504504
$this->doCommitDelete($model);
505505

506-
} elseif (true === $model->getState()->is('dirty')) {
506+
} elseif (true === $model->isDirty()) {
507507
$this->doCommitUpdate($model);
508508

509509
} else {
@@ -628,7 +628,7 @@ public function convertAttributeValue($dataType, $value)
628628
protected function shouldCommit(Model $model)
629629
{
630630
$state = $model->getState();
631-
return true === $state->is('dirty') || $state->is('new') || $state->is('deleting');
631+
return $model->isDirty() || $state->is('new') || $state->is('deleting');
632632
}
633633

634634
/**

0 commit comments

Comments
 (0)