Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 14, 2025
1 parent d72dcf0 commit 569594b
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,16 +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 {
// if the value here is an empty array, the target ids are already stored
// in the elements_sites.content column, as an empty array;
// meaning the content was saved since v5.3.0 and the field is supposed to be empty;
// see https://github.com/craftcms/cms/issues/16191
$query->andWhere(['elements.id' => []]);
$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

0 comments on commit 569594b

Please sign in to comment.