Skip to content

Commit

Permalink
Fixed #3846
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 14, 2019
1 parent d210345 commit cb35dbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Craft CMS 3.x

## Unreleased

### Fixed
- Fixed a bug where the `relatedTo` element query param could include results for elements that were related via soft-deleted Matrix blocks. ([#3846](https://github.com/craftcms/cms/issues/3846))

## 3.1.11 - 2019-02-14

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/elements/db/ElementRelationParamParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,17 @@ private function _subparse($relCriteria)

$sourcesAlias = 'sources' . $this->_relateSourcesCount;
$targetMatrixBlocksAlias = 'target_matrixblocks' . $this->_relateTargetMatrixBlocksCount;
$targetMatrixElementsAlias = 'target_matrixelements' . $this->_relateTargetMatrixBlocksCount;

$subQuery = (new Query())
->select([$sourcesAlias . '.targetId'])
->from([$sourcesAlias => Table::RELATIONS])
->innerJoin(Table::MATRIXBLOCKS . ' ' . $targetMatrixBlocksAlias, "[[{$targetMatrixBlocksAlias}.id]] = [[{$sourcesAlias}.sourceId]]")
->innerJoin(Table::ELEMENTS . ' ' . $targetMatrixElementsAlias, "[[{$targetMatrixElementsAlias}.id]] = [[{$targetMatrixBlocksAlias}.id]]")
->where([
$targetMatrixBlocksAlias . '.ownerId' => $relElementIds,
$targetMatrixBlocksAlias . '.fieldId' => $fieldModel->id,
$targetMatrixElementsAlias . '.dateDeleted' => null,
]);

if ($relCriteria['sourceSite']) {
Expand All @@ -327,13 +330,16 @@ private function _subparse($relCriteria)
} else {
$this->_relateSourceMatrixBlocksCount++;
$sourceMatrixBlocksAlias = 'source_matrixblocks' . $this->_relateSourceMatrixBlocksCount;
$sourceMatrixElementsAlias = 'source_matrixelements' . $this->_relateSourceMatrixBlocksCount;
$matrixBlockTargetsAlias = 'matrixblock_targets' . $this->_relateSourceMatrixBlocksCount;

$subQuery = (new Query())
->select([$sourceMatrixBlocksAlias . '.ownerId'])
->from([$sourceMatrixBlocksAlias => Table::MATRIXBLOCKS])
->innerJoin(Table::ELEMENTS . ' ' . $sourceMatrixElementsAlias, "[[{$sourceMatrixElementsAlias}.id]] = [[{$sourceMatrixBlocksAlias}.id]]")
->innerJoin(Table::RELATIONS . ' ' . $matrixBlockTargetsAlias, "[[{$matrixBlockTargetsAlias}.sourceId]] = [[{$sourceMatrixBlocksAlias}.id]]")
->where([
$sourceMatrixElementsAlias . '.dateDeleted' => null,
$matrixBlockTargetsAlias . '.targetId' => $relElementIds,
$sourceMatrixBlocksAlias . '.fieldId' => $fieldModel->id
]);
Expand Down

0 comments on commit cb35dbb

Please sign in to comment.