Skip to content

Commit

Permalink
[5.3] Fixes #15077 - QueryBuilder whereIn does not consider raw expre…
Browse files Browse the repository at this point in the history
…ssions (#15078)

* Fixes #15077 - QueryBuilder whereIn does not consider raw expressions

* style ci changes

* style ci changes
  • Loading branch information
VinceG authored and taylorotwell committed Aug 27, 2016
1 parent ed05e5d commit 15de9a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,11 @@ public function whereIn($column, $values, $boolean = 'and', $not = false)

$this->wheres[] = compact('type', 'column', 'values', 'boolean');

$this->addBinding($values, 'where');
foreach ($values as $value) {
if (! $value instanceof Expression) {
$this->addBinding($value, 'where');
}
}

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ public function testBasicWhereNotIns()
$this->assertEquals([0 => 1, 1 => 1, 2 => 2, 3 => 3], $builder->getBindings());
}

public function testRawWhereIns()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereIn('id', [new Raw(1)]);
$this->assertEquals('select * from "users" where "id" in (1)', $builder->toSql());

$builder = $this->getBuilder();
$builder->select('*')->from('users')->where('id', '=', 1)->orWhereIn('id', [new Raw(1)]);
$this->assertEquals('select * from "users" where "id" = ? or "id" in (1)', $builder->toSql());
$this->assertEquals([0 => 1], $builder->getBindings());
}

public function testEmptyWhereIns()
{
$builder = $this->getBuilder();
Expand Down

0 comments on commit 15de9a1

Please sign in to comment.