Skip to content

Commit

Permalink
Fixed #15570
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 28, 2024
1 parent 7e14327 commit 2ce4b5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592))
- Fixed a bug where tabs within field layout designers weren’t always getting positioned correctly when wrapped. ([#15590](https://github.com/craftcms/cms/issues/15590))
- Fixed a bug where editable table rows’ action buttons were misaligned for newly-created rows. ([#15602](https://github.com/craftcms/cms/issues/15602))
- Fixed a bug where relational fields’ element query results weren’t limited to the selected relations if the `id` param was overridden. ([#15570](https://github.com/craftcms/cms/issues/15570))

## 5.3.6 - 2024-08-26

Expand Down
12 changes: 9 additions & 3 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\base\NestedElementInterface;
use craft\base\RelationalFieldInterface;
use craft\behaviors\EventBehavior;
use craft\db\FixedOrderExpression;
use craft\db\Query;
use craft\db\Table as DbTable;
use craft\elements\conditions\ElementCondition;
Expand Down Expand Up @@ -674,9 +675,14 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
->siteId($this->targetSiteId($element));

if (is_array($value)) {
$query
->id(array_values(array_filter($value)))
->fixedOrder();
$value = array_values(array_filter($value));
if (!empty($value)) {
$query
->andWhere(['elements.id' => $value])
->orderBy([new FixedOrderExpression('elements.id', $value, Craft::$app->getDb())]);
} else {
$query->andWhere('0 = 1');
}
} elseif ($value === null && $element?->id && $this->isFirstInstance($element)) {
// If $value is null, the element + field haven’t been saved since updating to Craft 5.3+,
// or since the field was added to the field layout. So only actually look at the `relations` table
Expand Down

0 comments on commit 2ce4b5b

Please sign in to comment.