Skip to content

Commit

Permalink
no need for alias when it's the same as the table name
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed May 28, 2018
1 parent 76f252c commit 83eda31
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Relationship/RegularRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public function joinSelect(
callable $sub = null
) : void
{
$foreignTable = $this->foreignTableName;
$spec = "{$foreignTable} AS {$foreignAlias}";
$spec = $this->foreignTableName;
if ($spec !== $foreignAlias) {
$spec .= " AS {$foreignAlias}";
}

$cond = [];
foreach ($this->on as $nativeCol => $foreignCol) {
Expand Down
2 changes: 1 addition & 1 deletion tests/MapperSelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testJoinWithSubRelated()
*
FROM
authors
LEFT JOIN threads AS threads ON authors.author_id = threads.author_id
LEFT JOIN threads ON authors.author_id = threads.author_id
INNER JOIN taggings AS taggings_alias ON threads.thread_id = taggings_alias.thread_id
JOIN tags AS tag ON taggings_alias.tag_id = tag.tag_id
';
Expand Down
4 changes: 2 additions & 2 deletions tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function testLeftJoinWith()
FROM
threads
LEFT JOIN replies AS replies ON threads.thread_id = replies.thread_id
LEFT JOIN replies ON threads.thread_id = replies.thread_id
ORDER BY
replies.reply_id DESC';

Expand All @@ -418,7 +418,7 @@ public function testInnerJoinWith()
FROM
threads
INNER JOIN replies AS replies ON threads.thread_id = replies.thread_id
INNER JOIN replies ON threads.thread_id = replies.thread_id
ORDER BY
replies.reply_id DESC';

Expand Down

0 comments on commit 83eda31

Please sign in to comment.