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;