diff --git a/config/system.php b/config/system.php index 95f4c797ff..bc71633208 100644 --- a/config/system.php +++ b/config/system.php @@ -168,6 +168,19 @@ 'update_references' => true, + /* + |-------------------------------------------------------------------------- + | Always Augment to Query + |-------------------------------------------------------------------------- + | + | With this enabled, Statamic will always augment relationship fields to + | query builders. With it disabled `max_items: 1` fields are augmented to the + | referenced entry object. + | + */ + + 'always_augment_to_query' => false, + /* |-------------------------------------------------------------------------- | Row ID handle diff --git a/src/Fieldtypes/Assets/Assets.php b/src/Fieldtypes/Assets/Assets.php index e60f1b31cb..d70e233244 100644 --- a/src/Fieldtypes/Assets/Assets.php +++ b/src/Fieldtypes/Assets/Assets.php @@ -265,7 +265,9 @@ public function augment($values) $query = new OrderedQueryBuilder($query, $ids); - return $single ? Blink::once($key, fn () => $query->first()) : $query; + return $single && ! config('statamic.system.always_augment_to_query', false) + ? Blink::once($key, fn () => $query->first()) + : $query; } public function shallowAugment($values) diff --git a/src/Fieldtypes/Entries.php b/src/Fieldtypes/Entries.php index b51f0706ce..29a9b96e78 100644 --- a/src/Fieldtypes/Entries.php +++ b/src/Fieldtypes/Entries.php @@ -370,7 +370,9 @@ public function augment($values) $query = $this->queryBuilder($values); - return $single ? Blink::once($key, fn () => $query->first()) : $query; + return $single && ! config('statamic.system.always_augment_to_query', false) + ? Blink::once($key, fn () => $query->first()) + : $query; } public function shallowAugment($values) diff --git a/src/Fieldtypes/Terms.php b/src/Fieldtypes/Terms.php index 440fa33315..c3b7dd1bd0 100644 --- a/src/Fieldtypes/Terms.php +++ b/src/Fieldtypes/Terms.php @@ -123,7 +123,9 @@ public function augment($values) $query = $this->queryBuilder($values); - return $single ? Blink::once($key, fn () => $query->first()) : $query; + return $single && ! config('statamic.system.always_augment_to_query', false) + ? Blink::once($key, fn () => $query->first()) + : $query; } private function queryBuilder($values) diff --git a/src/Fieldtypes/Users.php b/src/Fieldtypes/Users.php index b3e9317701..641d7d99f5 100644 --- a/src/Fieldtypes/Users.php +++ b/src/Fieldtypes/Users.php @@ -180,11 +180,15 @@ protected function getItemsForPreProcessIndex($values): Collection public function augment($values) { + $single = $this->config('max_items') === 1; + $ids = Arr::wrap($values); $query = (new OrderedQueryBuilder(User::query(), $ids))->whereIn('id', $ids); - return $this->config('max_items') === 1 ? $query->first() : $query; + return $single && ! config('statamic.system.always_augment_to_query', false) + ? $query->first() + : $query; } public function shallowAugment($values)