diff --git a/src/Entries/EntryQueryBuilder.php b/src/Entries/EntryQueryBuilder.php index 316b01b5..973a234c 100644 --- a/src/Entries/EntryQueryBuilder.php +++ b/src/Entries/EntryQueryBuilder.php @@ -214,11 +214,15 @@ protected function getJsonCasts(): IlluminateCollection $wheres = collect($this->builder->getQuery()->wheres); $collectionWhere = $wheres->firstWhere('column', 'collection'); - if ( - ! $collectionWhere - || ! isset($collectionWhere['value']) - || ! ($collection = Collection::find($collectionWhere['value'])) - ) { + if (! $collectionWhere) { + return collect([]); + } + + if (isset($collectionWhere['values']) && count($collectionWhere['values']) == 1) { + $collectionWhere['value'] = $collectionWhere['values'][0]; + } + + if (! isset($collectionWhere['value']) || ! $collection = Collection::find($collectionWhere['value'])) { return collect([]); } diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 500fbb61..e1b22561 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -770,14 +770,19 @@ public function entries_can_be_ordered_by_a_float_json_field() Blueprint::shouldReceive('in')->with('collections/posts')->andReturn(collect(['posts' => $blueprint])); Collection::make('posts')->save(); - EntryFactory::id('1')->slug('post-1')->collection('posts')->data(['title' => 'Post 1', 'float' => 3.3])->create(); - EntryFactory::id('2')->slug('post-2')->collection('posts')->data(['title' => 'Post 2', 'float' => 5.5])->create(); - EntryFactory::id('3')->slug('post-3')->collection('posts')->data(['title' => 'Post 3', 'float' => 1.1])->create(); + EntryFactory::id('1')->slug('post-1')->collection('posts')->data(['title' => 'Post 1', 'float' => '9.5'])->create(); + EntryFactory::id('2')->slug('post-2')->collection('posts')->data(['title' => 'Post 2', 'float' => '10.2'])->create(); + EntryFactory::id('3')->slug('post-3')->collection('posts')->data(['title' => 'Post 3', 'float' => '8.7'])->create(); $entries = Entry::query()->where('collection', 'posts')->orderBy('float', 'asc')->get(); $this->assertCount(3, $entries); $this->assertEquals(['Post 3', 'Post 1', 'Post 2'], $entries->map->title->all()); + + $entries = Entry::query()->whereIn('collection', ['posts'])->orderBy('float', 'asc')->get(); + + $this->assertCount(3, $entries); + $this->assertEquals(['Post 3', 'Post 1', 'Post 2'], $entries->map->title->all()); } #[Test]