Fixes #3182 Fixes lazy loading of fields when query was created in default stage

When a DataObject query is created in the default stage (stage.Stage), then the
stage is changed to something else (stage.Live), the query itself runs
correctly against stage.Stage. However, lazy loaded fields incorrectly run
against stage.Live. This is due to DataQuery parameters not being saved when
the default stage is active.

This commit fixes this bug by always saving query params, even when the default
stage was active at the time of query creation.
This commit is contained in:
Craig Weber 2014-06-02 12:25:27 +00:00 committed by Damian Mooyman
parent 3074dd7d00
commit e732aee6eb

View File

@ -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
*/