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:
Loz Calver 2016-05-10 09:02:37 +01:00
commit a596bd4d6a

View File

@ -749,6 +749,27 @@ class VersionedTest extends SapphireTest {
Versioned::set_reading_mode($originalMode); 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 * Tests that reading mode persists between requests
*/ */