Skip to content

Commit

Permalink
Fixes #3182 Fixes lazy loading of fields when query was created in de…
Browse files Browse the repository at this point in the history
…fault 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.
  • Loading branch information
crgwbr authored and Damian Mooyman committed May 10, 2016
1 parent 3074dd7 commit e732aee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/model/VersionedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,27 @@ public function testLazyLoadFields() {
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
*/
Expand Down

0 comments on commit e732aee

Please sign in to comment.