From 8da8546fbf598322445a0924a1a1df7ddaa1c965 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Mon, 18 Jan 2021 00:20:34 +0300 Subject: [PATCH] Fix joins readme & new test case (#37) --- README.md | 4 ++-- tests/BuilderTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d951af2..6e26b03 100644 --- a/README.md +++ b/README.md @@ -158,8 +158,8 @@ SELECT * FROM `table` GLOBAL ANY LEFT JOIN `another_table` AS `alias` USING `col For performing subquery as first argument you can pass closure or builder. ```php -$builder->from('table')->join(function ($query) { - $query->select('column1', 'column2')->from('table2'); +$builder->from('table')->join(function ($join) { + $join->query()->select('column1', 'column2')->from('table2'); }, 'any', 'left', ['column1', 'column2']); $builder->from('table')->join($builder->select('column1', 'column2')->from('table2'), 'any', 'left', ['column1', 'column2']); diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index c005b69..e25321b 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -397,6 +397,11 @@ public function test_join_with_closure() $builder = $this->getBuilder()->anyLeftJoin($this->getBuilder()->from('table'), ['column']); $this->assertEquals('SELECT * ANY LEFT JOIN (SELECT * FROM `table`) USING `column`', $builder->toSql()); + + $builder->from('table')->join(function ($join) { + $join->query()->select('column1', 'column2')->from('table2'); + }, 'any', 'left', ['column1', 'column2']); + $this->assertEquals('SELECT * FROM `table` ANY LEFT JOIN (SELECT `column1`, `column2` FROM `table2`) USING `column1`, `column2`', $builder->toSql()); } public function test_preWheres()