diff --git a/src/Relationship/RegularRelationship.php b/src/Relationship/RegularRelationship.php index b5e715b..0e033f2 100644 --- a/src/Relationship/RegularRelationship.php +++ b/src/Relationship/RegularRelationship.php @@ -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) { diff --git a/tests/MapperSelectTest.php b/tests/MapperSelectTest.php index a0f3364..4b39815 100644 --- a/tests/MapperSelectTest.php +++ b/tests/MapperSelectTest.php @@ -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 '; diff --git a/tests/MapperTest.php b/tests/MapperTest.php index 6c7dcd6..2a67c2e 100644 --- a/tests/MapperTest.php +++ b/tests/MapperTest.php @@ -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'; @@ -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';