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
This commit is contained in:
Sam Minnee 2009-08-19 04:59:40 +00:00
parent e0e12aeb40
commit dfbd16e140
2 changed files with 9 additions and 1 deletions

View File

@ -2096,6 +2096,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return ( return (
array_key_exists($field, $this->record) array_key_exists($field, $this->record)
|| $this->hasDatabaseField($field) || $this->hasDatabaseField($field)
|| array_key_exists($field, $this->db()) // Needed for composite fields
|| $this->hasMethod("get{$field}") || $this->hasMethod("get{$field}")
); );
} }

View File

@ -15,6 +15,12 @@ class MoneyTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/MoneyTest.yml'; static $fixture_file = 'sapphire/tests/model/MoneyTest.yml';
function testMoneyFieldsReturnedAsObjects() {
$obj = $this->objFromFixture('MoneyTest_DataObject', 'test1');
$this->assertType('Money', $obj->MyMoney);
}
function testLoadFromFixture() { function testLoadFromFixture() {
$obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1');
@ -32,6 +38,7 @@ class MoneyTest extends SapphireTest {
$this->assertNotContains('MyMoney', array_keys($changed)); $this->assertNotContains('MyMoney', array_keys($changed));
// With changes // With changes
$this->assertType('Money', $obj->MyMoney);
$obj->MyMoney->setAmount(99); $obj->MyMoney->setAmount(99);
$changed = $obj->getChangedFields(); $changed = $obj->getChangedFields();
$this->assertContains('MyMoney', array_keys($changed)); $this->assertContains('MyMoney', array_keys($changed));