Skip to content
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
5 changes: 5 additions & 0 deletions src/Fieldtypes/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ public function getColumns()

protected function getItemsForPreProcessIndex($values): SupportCollection
{
// Nothing selected, so there's nothing to go looking for.
if (empty(Arr::wrap($values))) {
return $this->collect([]);
}

// These are the entries a query for them in any status would find, so they aren't looked for a second time.
return Entry::applySubstitutions($this->entriesInTheirSite($values)->unique->id()->values());
}
Expand Down
5 changes: 5 additions & 0 deletions src/Stache/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ private function comparesEqualityAsStrings($where)

protected function filterWhereIn($values, $where)
{
// Nothing can be in an empty list.
if (empty($where['values'])) {
return $values->take(0);
}

$lookup = array_flip(array_map($this->normalizeLookupValue(...), $where['values']));

return $values->filter(
Expand Down
11 changes: 11 additions & 0 deletions tests/Data/Entries/EntryQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public function entries_are_found_using_or_where_in()
$this->assertEquals(['Post 1', 'Post 2', 'Post 4', 'Post 5'], $entries->map->title->all());
}

#[Test]
public function nothing_is_found_in_an_empty_list()
{
$this->createDummyCollectionAndEntries();

$this->assertSame([], Entry::query()->whereIn('id', [])->get()->map->id()->all());
$this->assertSame([], Entry::query()->whereIn('title', [])->get()->map->id()->all());
$this->assertSame(['id-1'], Entry::query()->where('title', 'Post 1')->orWhereIn('id', [])->get()->map->id()->all());
$this->assertSame(['id-1', 'id-2', 'id-3'], Entry::query()->whereNotIn('id', [])->get()->map->id()->all());
}

#[Test]
public function entries_are_ordered_the_way_a_data_collection_sorts_their_values()
{
Expand Down
11 changes: 11 additions & 0 deletions tests/Fieldtypes/EntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public function it_returns_empty_collection_when_preprocessing_index_and_max_ite
$this->assertEquals([], $preProcessed->all());
}

#[Test]
public function it_returns_an_empty_collection_when_preprocessing_index_and_nothing_is_selected()
{
foreach ([null, []] as $value) {
$preProcessed = $this->fieldtype()->preProcessIndex($value);

$this->assertInstanceOf(Collection::class, $preProcessed);
$this->assertCount(0, $preProcessed);
}
}

#[Test]
public function it_includes_drafts_when_pre_processing_for_index()
{
Expand Down
Loading