From a83af519032dec4ef83c5f44beb799111f2091e2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 21 Oct 2016 23:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84view?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=92=8Cjoin=E6=96=B9=E6=B3=95=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8=E4=B8=8D=E5=B8=A6=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E7=9A=84=E8=A1=A8=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 8a8617ff..e5c9b978 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -669,7 +669,11 @@ class Query $table = array_shift($join); } } else { - $table = trim($join); + $prefix = $this->prefix; + $table = trim($join); + if ($prefix && false === strpos($table, '(') && false === strpos($table, '.') && 0 !== strpos($table, $prefix) && 0 !== strpos($table, '__')) { + $table = $this->getTable($table); + } if (strpos($table, ' ') && !strpos($table, ')')) { list($table, $alias) = explode(' ', $table); $table = [$table => $alias]; @@ -763,13 +767,17 @@ class Query } } else { $fields = []; + $prefix = $this->prefix; if (is_array($join)) { // 支持数据表别名 - list($join, $alias, $table) = array_pad($join, 3, ''); + list($table, $alias) = ecch($join); + } elseif ($prefix && 0 !== strpos($join, $prefix) && 0 !== strpos($join, '__')) { + $table = $this->getTable($join); + $alias = $join; } else { $alias = $join; } - $table = !empty($table) ? $table : $this->getTable($join); + $table = isset($table) ? [$table => $alias] : $alias; if (true === $field) { $fields = $alias . '.*'; } else { @@ -793,9 +801,9 @@ class Query } $this->field($fields); if ($on) { - $this->join($table . ' ' . $alias, $on, $type); + $this->join($table, $on, $type); } else { - $this->table($table . ' ' . $alias); + $this->table($table); } } return $this;