Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When normalising relation field value, respect the empty array #16428

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 field layout elements’ action menus could have an empty action group.
- Fixed a bug where Single section entries could be duplicated after running the `entry-types/merge` command. ([#16394](https://github.com/craftcms/cms/issues/16394))
- Fixed a styling bug with the system message modal. ([#16410](https://github.com/craftcms/cms/issues/16410))
- Fixed a bug where relational fields could eager-load elements from a different instance of the same field, if one of the instances had no relations. ([#16191](https://github.com/craftcms/cms/issues/16191))

## 5.5.9 - 2025-01-06

Expand Down
7 changes: 2 additions & 5 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,9 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed

if (is_array($value)) {
$value = array_values(array_filter($value));
$query->andWhere(['elements.id' => $value]);
if (!empty($value)) {
$query
->andWhere(['elements.id' => $value])
->orderBy([new FixedOrderExpression('elements.id', $value, Craft::$app->getDb())]);
} else {
$query->andWhere('0 = 1');
$query->orderBy([new FixedOrderExpression('elements.id', $value, Craft::$app->getDb())]);
}
} 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+,
Expand Down