diff --git a/core/model/DataObject.php b/core/model/DataObject.php index b28248bc4..8b66f9c25 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -1844,6 +1844,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity public function getChangedFields($databaseFieldsOnly = false, $changeLevel = 1) { $changedFields = array(); + // Update the changed array with references to changed obj-fields + foreach($this->record as $k => $v) { + if(is_object($v) && method_exists($v, 'isChanged') && $v->isChanged()) { + $this->changed[$k] = true; + } + } + if($databaseFieldsOnly) { $customDatabaseFields = $this->customDatabaseFields(); $fields = array_intersect_key($this->changed, $customDatabaseFields); diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 0a5ba28a7..e2d87c9e0 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -23,6 +23,13 @@ class MoneyTest extends SapphireTest { $this->assertEquals($obj->MyMoney->getAmount(), 1.23); } + function testDataObjectChangedFields() { + $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); + $obj->MyMoney->setAmount(99); + $changed = $obj->getChangedFields(); + $this->assertContains('MyMoney', array_keys($changed)); + } + function testCanOverwriteSettersWithNull() { $obj = new MoneyTest_DataObject();