From 7c49bd442067c1d4ca05ec9ad590156155b21a24 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 6 Oct 2016 21:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bjoin=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 16 +++++++--------- library/think/db/Query.php | 3 --- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 80defb75..75c4aa86 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -179,11 +179,8 @@ abstract class Builder */ protected function parseTable($tables, $options = []) { - if (is_string($tables)) { - $tables = (array) $tables; - } $item = []; - foreach ($tables as $table) { + foreach ((array) $tables as $table) { $table = $this->parseSqlTable($table); if (isset($options['alias'][$table])) { $item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]); @@ -438,13 +435,14 @@ abstract class Builder if (!empty($join)) { foreach ($join as $item) { list($table, $type, $on) = $item; - if (!empty($options['alias'])) { - foreach ($options['alias'] as $key => $val) { - $on = str_replace($key . '.', $this->parseKey($val, $options) . '.', $on); - } + $condition = []; + foreach ((array) $on as $val) { + list($val1, $val2) = explode('=', $val, 2); + $condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options); } + $table = $this->parseTable($table, $options); - $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . $on; + $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . implode(' AND ', $condition); } } return $joinStr; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c6b49ebf..79933838 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -696,9 +696,6 @@ class Query $this->alias([$table => $alias]); } } - if (is_array($condition)) { - $condition = implode(' AND ', $condition); - } $this->options['join'][] = [$table, strtoupper($type), $condition]; } return $this;