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 (
array_key_exists($field, $this->record)
|| $this->hasDatabaseField($field)
|| array_key_exists($field, $this->db()) // Needed for composite fields
|| $this->hasMethod("get{$field}")
);
}

View File

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