mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #5447 from tractorcow/pull/3183-lazy-loading-stage
Fixes #3182 Fixes lazy loading of fields when query was created in default stage
This commit is contained in:
commit
a596bd4d6a
@ -749,6 +749,27 @@ class VersionedTest extends SapphireTest {
|
||||
Versioned::set_reading_mode($originalMode);
|
||||
}
|
||||
|
||||
public function testLazyLoadFieldsRetrieval() {
|
||||
// Set reading mode to Stage
|
||||
Versioned::set_stage(Versioned::DRAFT);
|
||||
|
||||
// Create object only in reading stage
|
||||
$original = new VersionedTest_Subclass();
|
||||
$original->ExtraField = 'Foo';
|
||||
$original->write();
|
||||
|
||||
// Query for object using base class
|
||||
$query = VersionedTest_DataObject::get()->filter('ID', $original->ID);
|
||||
|
||||
// Set reading mode to Live
|
||||
Versioned::set_stage(Versioned::LIVE);
|
||||
|
||||
$fetched = $query->first();
|
||||
$this->assertTrue($fetched instanceof VersionedTest_Subclass);
|
||||
$this->assertEquals($original->ID, $fetched->ID); // Eager loaded
|
||||
$this->assertEquals($original->ExtraField, $fetched->ExtraField); // Lazy loaded
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that reading mode persists between requests
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user