Skip to content

Commit 0a00d12

Browse files
author
Ethan
committed
join
1 parent 1c8b9cd commit 0a00d12

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Builder.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,16 @@ public function wherePk($id, $primaryKeyField = null)
704704
*/
705705
public function join($table, $on)
706706
{
707+
$asName = '';
708+
if (preg_match('/^(.+?)\s+(as\s+)?(\w+)$/i', $table, $res)) {
709+
$table = $res[1];
710+
$asName = $res[3];
711+
$asName = ' AS ' . self::addTableQuote($asName);
712+
}
713+
707714
$type = 'JOIN';
708-
$table = self::addPrefix($table);
715+
716+
$table = self::addPrefix($table) . $asName;
709717
$this->join[] = compact('type', 'table', 'on');
710718
return $this;
711719
}
@@ -719,8 +727,15 @@ public function join($table, $on)
719727
*/
720728
public function leftJoin($table, $on)
721729
{
730+
$asName = '';
731+
if (preg_match('/^(.+?)\s+(as\s+)?(\w+)$/i', $table, $res)) {
732+
$table = $res[1];
733+
$asName = $res[3];
734+
$asName = ' AS ' . self::addTableQuote($asName);
735+
}
736+
722737
$type = 'LEFT JOIN';
723-
$table = self::addPrefix($table);
738+
$table = self::addPrefix($table) . $asName;
724739
$this->join[] = compact('type', 'table', 'on');
725740
return $this;
726741
}

0 commit comments

Comments
 (0)