diff --git a/src/Entries/EntryQueryBuilder.php b/src/Entries/EntryQueryBuilder.php index fcf9e016..316b01b5 100644 --- a/src/Entries/EntryQueryBuilder.php +++ b/src/Entries/EntryQueryBuilder.php @@ -55,9 +55,7 @@ protected function column($column) $column = 'origin_id'; } - $columns = Blink::once('eloquent-entry-data-column-mappings', fn () => array_merge(self::COLUMNS, (new EloquentEntry)->getDataColumnMappings($this->builder->getModel()))); - - if (! in_array($column, $columns)) { + if (! in_array($column, $this->entryColumnsAndMappings())) { if (! Str::startsWith($column, 'data->')) { $column = 'data->'.$column; } @@ -145,7 +143,7 @@ private function ensureCollectionsAreQueriedForStatusQuery(): void // If no IDs were queried, fall back to all collections. $ids->isEmpty() ? $this->whereIn('collection', Collection::handles()) - : $this->whereIn('collection', app(static::class)->whereIn('id', $ids)->pluck('collection')->map(fn ($collection) => $collection?->handle)->filter()->unique()->values()); + : $this->whereIn('collection', app('statamic.eloquent.entries.model')::query()->whereIn('id', $ids)->distinct('collection')->pluck('collection')->values()); } private function getCollectionsForStatusQuery(): \Illuminate\Support\Collection @@ -233,4 +231,18 @@ protected function getJsonCasts(): IlluminateCollection }) ->filter(); } + + public function pluck($column, $key = null) + { + if (! $key && in_array($column, $this->entryColumnsAndMappings())) { + return $this->builder->pluck($column, $key); + } + + return parent::pluck($column, $key); + } + + private function entryColumnsAndMappings() + { + return Blink::once('eloquent-entry-data-column-mappings', fn () => array_merge(self::COLUMNS, (new EloquentEntry)->getDataColumnMappings($this->builder->getModel()))); + } }