BUGFIX Inspecting the change status of all CompositeDBFields when invoking DataObject->getChangedFields(), as their value setting is not performed through DataObject->setField(), it doesn't trigger the built-in change detection.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77667 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-05-23 05:32:16 +00:00
parent cc93959d7f
commit 9f7bbc57d0
2 changed files with 14 additions and 0 deletions

View File

@ -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);

View File

@ -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();