Skip to content

Commit 0bb9dd7

Browse files
authored
Merge pull request #147 from ikerasLT/master
Fix nested where binding issue
2 parents 4ac8702 + 55a4f34 commit 0bb9dd7

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ protected function getNestedClauses(array $where) : string
164164
return "";
165165
}
166166

167-
$this->currentBinding++;
168-
169167
return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres);
170168
}
171169

@@ -175,8 +173,6 @@ protected function getColumnClauses(array $where) : string
175173
return "";
176174
}
177175

178-
$this->currentBinding++;
179-
180176
return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}";
181177
}
182178

tests/Integration/CachedBuilder/WhereRawTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,19 @@ public function testNestedWhereRawClauses()
8989

9090
$this->assertEquals($expectedIds, $authors->pluck("id")->toArray());
9191
}
92+
93+
public function testNestedWhereRawWithBindings()
94+
{
95+
$books = (new Book)
96+
->where(function ($query) {
97+
$query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]);
98+
})->get();
99+
100+
$uncachedBooks = (new UncachedBook)
101+
->where(function ($query) {
102+
$query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]);
103+
})->get();
104+
105+
$this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id"));
106+
}
92107
}

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)