修正Query的join方法

This commit is contained in:
thinkphp
2016-10-09 15:07:19 +08:00
parent e3ec75d001
commit b754709dbf
2 changed files with 16 additions and 9 deletions

View File

@@ -442,8 +442,12 @@ abstract class Builder
list($table, $type, $on) = $item;
$condition = [];
foreach ((array) $on as $val) {
list($val1, $val2) = explode('=', $val, 2);
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
if (strpos($val, '=')) {
list($val1, $val2) = explode('=', $val, 2);
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
} else {
$condition[] = $val;
}
}
$table = $this->parseTable($table, $options);

View File

@@ -666,22 +666,25 @@ class Query
$prefix = $this->prefix;
// 传入的表名为数组
if (is_array($join)) {
if (count($join) > 1) {
$prefix = array_pop($join);
}
if (0 !== $key = key($join)) {
// 设置了键名则键名为表名,键值作为表的别名
$table = $key;
if (false === strpos($table, '.')) {
$table = $prefix . $table;
}
$alias = array_shift($join);
$this->alias([$table => $alias]);
$table = [$table => $alias];
} else {
$table = array_shift($join);
if (false === strpos($table, '.')) {
$table = $prefix . $table;
}
}
if (count($join)) {
// 有设置第二个元素则把第二元素作为表前缀
$table = (string) current($join) . $table;
} elseif (false === strpos($table, '.')) {
// 加上默认的表前缀
$table = $prefix . $table;
}
} else {
$join = trim($join);
if (0 === strpos($join, '__')) {