mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
cc93959d7f
commit
9f7bbc57d0
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user