Merge pull request #6604 from andrewandante/FIX/hydrate-lazy-fields-on-dbobject

FIX load fields if lazy ones exists
This commit is contained in:
Daniel Hensby 2017-02-08 10:36:09 +00:00 committed by GitHub
commit d5c9edd7f7
2 changed files with 20 additions and 0 deletions

View File

@ -2721,6 +2721,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
return null; return null;
} }
if (!isset($this->record[$fieldName]) && isset($this->record[$fieldName . '_Lazy'])) {
$tableClass = $this->record[$fieldName . '_Lazy'];
$this->loadLazyFields($tableClass);
}
$value = isset($this->record[$fieldName]) $value = isset($this->record[$fieldName])
? $this->record[$fieldName] ? $this->record[$fieldName]
: null; : null;

View File

@ -150,6 +150,21 @@ class DataObjectLazyLoadingTest extends SapphireTest
); );
} }
public function testDBObjectLazyLoadedFields()
{
$subteam1 = $this->objFromFixture(SubTeam::class, 'subteam1');
$teams = DataObject::get(Team::class); // query parent class
$subteam1Lazy = $teams->find('ID', $subteam1->ID);
$subteam1DO = $subteam1->dbObject('SubclassDatabaseField');
$subteam1LazyDO = $subteam1Lazy->dbObject('SubclassDatabaseField');
$this->assertEquals(
$subteam1DO->getValue(),
$subteam1LazyDO->getValue()
);
}
public function testLazyLoadedFieldsSetField() public function testLazyLoadedFieldsSetField()
{ {
$subteam1 = $this->objFromFixture(SubTeam::class, 'subteam1'); $subteam1 = $this->objFromFixture(SubTeam::class, 'subteam1');