Skip to content

Commit 9c8d05e

Browse files
committed
fix: hasChanged() returns wrong result to mapped property
1 parent f422f3b commit 9c8d05e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

system/Entity/Entity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ public function hasChanged(?string $key = null): bool
256256
return $this->original !== $this->attributes;
257257
}
258258

259+
$key = $this->mapProperty($key);
260+
259261
// Key doesn't exist in either
260262
if (! array_key_exists($key, $this->original) && ! array_key_exists($key, $this->attributes)) {
261263
return false;

tests/system/Entity/EntityTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,24 @@ public function testHasChangedNoChange()
929929
$this->assertFalse($entity->hasChanged('default'));
930930
}
931931

932+
public function testHasChangedMappedNoChange()
933+
{
934+
$entity = $this->getEntity();
935+
936+
$entity->createdAt = null;
937+
938+
$this->assertFalse($entity->hasChanged('createdAt'));
939+
}
940+
941+
public function testHasChangedMappedChanged()
942+
{
943+
$entity = $this->getEntity();
944+
945+
$entity->createdAt = '2022-11-11 11:11:11';
946+
947+
$this->assertTrue($entity->hasChanged('createdAt'));
948+
}
949+
932950
public function testHasChangedWholeEntity()
933951
{
934952
$entity = $this->getEntity();

0 commit comments

Comments
 (0)