DbObject: improve "hasBeenModified" logic

This commit is contained in:
Thomas Gelf 2022-10-07 11:20:32 +02:00
parent 2196426ff5
commit 82269775f4

View File

@ -371,9 +371,27 @@ abstract class DbObject
if ($value === $this->properties[$key]) {
return $this;
}
if ($key === 'id' || substr($key, -3) === '_id') {
if ((int) $value === (int) $this->properties[$key]) {
return $this;
}
}
if ($this->hasBeenLoadedFromDb()) {
if ($value === $this->loadedProperties[$key]) {
unset($this->modifiedProperties[$key]);
if (empty($this->modifiedProperties)) {
$this->hasBeenModified = false;
}
} else {
$this->hasBeenModified = true;
$this->modifiedProperties[$key] = true;
}
} else {
$this->hasBeenModified = true;
$this->modifiedProperties[$key] = true;
}
$this->hasBeenModified = true;
$this->modifiedProperties[$key] = true;
$this->properties[$key] = $value;
return $this;
}