Skip to content

Commit 55a4f34

Browse files
author
Viktoras Morkūnas
committed
Fix whereHas query with nested whereRaw
1 parent b0efb66 commit 55a4f34

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"sebastian/phpcpd": "*",
3030
"symfony/thanks": "*",
3131
"predis/predis": "*",
32-
"codedungeon/phpunit-result-printer": "*"
32+
"codedungeon/phpunit-result-printer": "^0.19.10"
3333
},
3434
"autoload": {
3535
"psr-4": {

src/CacheKey.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ protected function getColumnClauses(array $where) : string
173173
return "";
174174
}
175175

176-
$this->currentBinding++;
177-
178176
return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}";
179177
}
180178

tests/Integration/CachedBuilderRelationshipsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,23 @@ public function testHasRelationshipResults()
3838
$this->assertNotEmpty($booksWithStores);
3939
$this->assertEquals($booksWithStores, $cachedResults);
4040
}
41+
42+
public function testWhereHasRelationship()
43+
{
44+
$books = (new Book)
45+
->with("stores")
46+
->whereHas("stores", function ($query) {
47+
$query->whereRaw('address like ?', ['%s%']);
48+
})
49+
->get();
50+
51+
$uncachedBooks = (new UncachedBook)
52+
->with("stores")
53+
->whereHas("stores", function ($query) {
54+
$query->whereRaw('address like ?', ['%s%']);
55+
})
56+
->get();
57+
58+
$this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id"));
59+
}
4160
}

0 commit comments

Comments
 (0)