Skip to content

Commit

Permalink
Convert eloquent builder to base in whereExists (#46460)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdebrauwer authored Mar 14, 2023
1 parent 38f022d commit 4126b40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ public function whereExists($callback, $boolean = 'and', $not = false)
// compile the whole thing in the grammar and insert it into the SQL.
$callback($query);
} else {
$query = $callback;
$query = $callback instanceof EloquentBuilder ? $callback->toBase() : $callback;
}

return $this->addWhereExistsQuery($query, $boolean, $not);
Expand Down
6 changes: 6 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,12 @@ public function testWhereExists()
$this->getBuilder()->select('*')->from('products')->where('products.id', '=', new Raw('"orders"."id"'))
);
$this->assertSame('select * from "orders" where "id" = ? or not exists (select * from "products" where "products"."id" = "orders"."id")', $builder->toSql());

$builder = $this->getBuilder();
$builder->select('*')->from('orders')->whereExists(
(new EloquentBuilder($this->getBuilder()))->select('*')->from('products')->where('products.id', '=', new Raw('"orders"."id"'))
);
$this->assertSame('select * from "orders" where exists (select * from "products" where "products"."id" = "orders"."id")', $builder->toSql());
}

public function testBasicJoins()
Expand Down

0 comments on commit 4126b40

Please sign in to comment.