From dfbd16e14087f0472697e280bdba601aa2a19598 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 19 Aug 2009 04:59:40 +0000 Subject: [PATCH] BUGFIX: Fixed querying of composite fields (broken due to inappropriate optimisation of hasField) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84796 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 1 + tests/model/MoneyTest.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index a687548f8..ea889769c 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2096,6 +2096,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity return ( array_key_exists($field, $this->record) || $this->hasDatabaseField($field) + || array_key_exists($field, $this->db()) // Needed for composite fields || $this->hasMethod("get{$field}") ); } diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 617e59562..ef6ec1686 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -15,6 +15,12 @@ class MoneyTest extends SapphireTest { static $fixture_file = 'sapphire/tests/model/MoneyTest.yml'; + function testMoneyFieldsReturnedAsObjects() { + $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); + $this->assertType('Money', $obj->MyMoney); + } + + function testLoadFromFixture() { $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); @@ -30,8 +36,9 @@ class MoneyTest extends SapphireTest { $curr = $obj->obj('MyMoney'); $changed = $obj->getChangedFields(); $this->assertNotContains('MyMoney', array_keys($changed)); - + // With changes + $this->assertType('Money', $obj->MyMoney); $obj->MyMoney->setAmount(99); $changed = $obj->getChangedFields(); $this->assertContains('MyMoney', array_keys($changed));