Skip to content

Commit ea7e88a

Browse files
committed
Add parsing for where doesnthave(), fixes #23
1 parent ed66393 commit ea7e88a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/CachedBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ protected function getWhereClauses(array $wheres = []) : string
8181
}
8282

8383
return $wheres->reduce(function ($carry, $where) {
84-
if (in_array($where['type'], ['Exists', 'Nested'])) {
85-
return $this->getWhereClauses($where['query']->wheres);
84+
if (in_array($where['type'], ['Exists', 'Nested', 'NotExists'])) {
85+
return '_' . strtolower($where['type']) . $this->getWhereClauses($where['query']->wheres);
8686
}
8787

8888
if ($where['type'] === 'Column') {

tests/Unit/CachedBuilderTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function testExistsRelationshipWhereClauseParsing()
507507
$authors = (new Author)->whereHas('books')
508508
->get();
509509

510-
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_and_authors.id_=_books.author_id';
510+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_exists_and_authors.id_=_books.author_id';
511511
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
512512

513513
$cachedResults = cache()->tags($tags)->get($key);
@@ -518,6 +518,26 @@ public function testExistsRelationshipWhereClauseParsing()
518518
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
519519
}
520520

521+
public function testDoesntHaveWhereClaseParsing()
522+
{
523+
$authors = (new Author)
524+
->doesntHave('books')
525+
->get();
526+
527+
$key = 'genealabslaravelmodelcachingtestsfixturesauthor_notexists_and_authors.id_=_books.author_id';
528+
$tags = ['genealabslaravelmodelcachingtestsfixturesauthor'];
529+
530+
$cachedResults = cache()
531+
->tags($tags)
532+
->get($key);
533+
$liveResults = (new UncachedAuthor)
534+
->doesntHave('books')
535+
->get();
536+
537+
$this->assertEmpty($authors->diffAssoc($cachedResults));
538+
$this->assertEmpty($liveResults->diffAssoc($cachedResults));
539+
}
540+
521541
public function testColumnsRelationshipWhereClauseParsing()
522542
{
523543
$author = (new Author)

0 commit comments

Comments
 (0)