Skip to content
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

SqlBuilder: allow setting multiple joins over the same toExpression #133

Merged
merged 2 commits into from
Dec 10, 2020
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 src/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function removeJoins(): self
private function join(string $type, string $toExpression, string $onExpression, array $args): self
{
$this->dirty();
$this->join[$toExpression] = [
$this->join[] = [
'type' => $type,
'table' => $toExpression,
'on' => $onExpression,
Expand Down
10 changes: 9 additions & 1 deletion tests/cases/unit/QueryBuilderTest.joins.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ class QueryBuilderJoinsTest extends QueryBuilderTestCase
[
'SELECT * FROM one AS [o] ' .
'LEFT JOIN two AS [t] ON (o.userId = t.userId) ' .
'LEFT JOIN %table ON (%table.id = tbl.t1_id) ' .
'LEFT JOIN %table ON (%table.id = tbl.t2_id) ' .
'INNER JOIN three AS [th] ON (t.userId = th.userId) ' .
'RIGHT JOIN four AS [f] ON (th.userId = f.userId)'
'RIGHT JOIN four AS [f] ON (th.userId = f.userId)',
't1',
't1',
't2',
't2'
],
$this->builder()
->from('one', 'o')
->select('*')
->joinLeft('two AS [t]', 'o.userId = t.userId')
->joinLeft('%table', '%table.id = tbl.t1_id', 't1', 't1')
->joinLeft('%table', '%table.id = tbl.t2_id', 't2', 't2')
->joinInner('three AS [th]', 't.userId = th.userId')
->joinRight('four AS [f]', 'th.userId = f.userId')
);
Expand Down