mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #6604 from andrewandante/FIX/hydrate-lazy-fields-on-dbobject
FIX load fields if lazy ones exists
This commit is contained in:
commit
d5c9edd7f7
@ -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;
|
||||||
|
@ -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');
|
||||||
|
Loading…
Reference in New Issue
Block a user