Skip to content

Commit

Permalink
Don't wipe preloaded query results when setting the 'with' param
Browse files Browse the repository at this point in the history
Fixes #1576
  • Loading branch information
brandonkelly committed May 22, 2018
1 parent ee7014a commit 3c9ab5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `craft\base\Plugin` now sets the default `$controllerNamespace` value to the plugin class’ namespace + `\controllers` or `\console\controllers`, depending on whether it’s a web or console request.
- Improved the contrast of success and error notices in the Control Panel to meet WCAG AA requirements. ([#2885](https://github.com/craftcms/cms/issues/2885))
- `fieldValue` is now a protected field handle. ([#2893](https://github.com/craftcms/cms/issues/2893))
- Craft will no longer discard any preloaded elements when setting the `with` param on an element query, fixing a bug where disabled Matrix blocks could show up in Live Preview if any nested fields were getting eager-loaded. ([#1576](https://github.com/craftcms/cms/issues/1576))

### Fixed
- Fixed a bug where the Plugin Store was listing featured plugins (e.g. “Recently Added”) in alphabetical order rather than the API-defined order. ([pixelandtonic/craftnet#83](https://github.com/pixelandtonic/craftnet/issues/83))
Expand Down
12 changes: 10 additions & 2 deletions src/elements/db/ElementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use craft\errors\SiteNotFoundException;
use craft\events\CancelableEvent;
use craft\events\PopulateElementEvent;
use craft\helpers\ArrayHelper;
use craft\helpers\Db;
use craft\helpers\ElementHelper;
use craft\helpers\StringHelper;
Expand Down Expand Up @@ -1042,6 +1043,9 @@ public function all($db = null)
{
// Cached?
if (($cachedResult = $this->getCachedResult()) !== null) {
if ($this->with) {
Craft::$app->getElements()->eagerLoadElements($this->elementType, $cachedResult, $this->with);
}
return $cachedResult;
}

Expand Down Expand Up @@ -1114,7 +1118,6 @@ public function getCachedResult()
// Make sure the criteria hasn't changed
if ($this->_resultCriteria !== $this->getCriteria()) {
$this->_result = null;

return null;
}

Expand Down Expand Up @@ -1142,7 +1145,12 @@ public function setCachedResult(array $elements)
*/
public function getCriteria(): array
{
return $this->toArray($this->criteriaAttributes(), [], false);
$attributes = $this->criteriaAttributes();

// Ignore the 'with' param
ArrayHelper::removeValue($attributes, 'with');

return $this->toArray($attributes, [], false);
}

/**
Expand Down

0 comments on commit 3c9ab5a

Please sign in to comment.