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
3 changes: 2 additions & 1 deletion src/Stache/Query/QueriesTaxonomizedEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ protected function addTaxonomyWheres()
->reduce(function ($ids, $where) {
$keys = $this->getKeysForTaxonomyWhereIn($where);

return $ids ? $ids->intersect($keys)->values() : $keys;
// Each "not in" excludes its own entries, so an entry in any of them is excluded.
return $ids ? $ids->concat($keys)->unique()->values() : $keys;
});

if ($entryIds) {
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/Entries/GetByTaxonomyTermsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ public function it_gets_entries_in_multiple_taxonomy_terms()
$this->assertEquals([2], Entry::query()->whereTaxonomyIn(['tags::meh', 'categories::events'])->whereTaxonomyIn(['tags::awesome', 'tags::rad'])->get()->map->id()->all());
}

#[Test]
public function it_excludes_entries_in_any_of_multiple_taxonomy_not_in_wheres()
{
Taxonomy::make('tags')->save();
Taxonomy::make('categories')->save();
Collection::make('blog')->taxonomies(['tags', 'categories'])->save();
EntryFactory::collection('blog')->id('1')->data(['tags' => ['rad'], 'categories' => ['news']])->create();
EntryFactory::collection('blog')->id('2')->data(['tags' => ['rad']])->create();
EntryFactory::collection('blog')->id('3')->data(['categories' => ['news']])->create();
EntryFactory::collection('blog')->id('4')->data(['tags' => ['meh']])->create();

$this->assertEquals([3, 4], Entry::query()->whereTaxonomyNotIn(['tags::rad'])->get()->map->id()->all());
$this->assertEquals([2, 4], Entry::query()->whereTaxonomyNotIn(['categories::news'])->get()->map->id()->all());
$this->assertEquals([4], Entry::query()->whereTaxonomyNotIn(['tags::rad'])->whereTaxonomyNotIn(['categories::news'])->get()->map->id()->all());
$this->assertEquals([4], Entry::query()->whereTaxonomyNotIn(['tags::rad', 'categories::news'])->get()->map->id()->all());
}

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