Skip to content

Fix nested where binding issue #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2018
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"sebastian/phpcpd": "*",
"symfony/thanks": "*",
"predis/predis": "*",
"codedungeon/phpunit-result-printer": "*"
"codedungeon/phpunit-result-printer": "^0.19.10"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 0 additions & 4 deletions src/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ protected function getNestedClauses(array $where) : string
return "";
}

$this->currentBinding++;

return "-" . strtolower($where["type"]) . $this->getWhereClauses($where["query"]->wheres);
}

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

$this->currentBinding++;

return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}";
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/CachedBuilder/WhereRawTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,19 @@ public function testNestedWhereRawClauses()

$this->assertEquals($expectedIds, $authors->pluck("id")->toArray());
}

public function testNestedWhereRawWithBindings()
{
$books = (new Book)
->where(function ($query) {
$query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]);
})->get();

$uncachedBooks = (new UncachedBook)
->where(function ($query) {
$query->whereRaw("title like ? or description like ? or published_at like ? or price like ?", ['%larravel%', '%larravel%', '%larravel%', '%larravel%',]);
})->get();

$this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id"));
}
}
19 changes: 19 additions & 0 deletions tests/Integration/CachedBuilderRelationshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@ public function testHasRelationshipResults()
$this->assertNotEmpty($booksWithStores);
$this->assertEquals($booksWithStores, $cachedResults);
}

public function testWhereHasRelationship()
{
$books = (new Book)
->with("stores")
->whereHas("stores", function ($query) {
$query->whereRaw('address like ?', ['%s%']);
})
->get();

$uncachedBooks = (new UncachedBook)
->with("stores")
->whereHas("stores", function ($query) {
$query->whereRaw('address like ?', ['%s%']);
})
->get();

$this->assertEquals($books->pluck("id"), $uncachedBooks->pluck("id"));
}
}