mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 16:12:49 +08:00
改进join方法解析
This commit is contained in:
@@ -179,11 +179,8 @@ abstract class Builder
|
|||||||
*/
|
*/
|
||||||
protected function parseTable($tables, $options = [])
|
protected function parseTable($tables, $options = [])
|
||||||
{
|
{
|
||||||
if (is_string($tables)) {
|
|
||||||
$tables = (array) $tables;
|
|
||||||
}
|
|
||||||
$item = [];
|
$item = [];
|
||||||
foreach ($tables as $table) {
|
foreach ((array) $tables as $table) {
|
||||||
$table = $this->parseSqlTable($table);
|
$table = $this->parseSqlTable($table);
|
||||||
if (isset($options['alias'][$table])) {
|
if (isset($options['alias'][$table])) {
|
||||||
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
|
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
|
||||||
@@ -438,13 +435,14 @@ abstract class Builder
|
|||||||
if (!empty($join)) {
|
if (!empty($join)) {
|
||||||
foreach ($join as $item) {
|
foreach ($join as $item) {
|
||||||
list($table, $type, $on) = $item;
|
list($table, $type, $on) = $item;
|
||||||
if (!empty($options['alias'])) {
|
$condition = [];
|
||||||
foreach ($options['alias'] as $key => $val) {
|
foreach ((array) $on as $val) {
|
||||||
$on = str_replace($key . '.', $this->parseKey($val, $options) . '.', $on);
|
list($val1, $val2) = explode('=', $val, 2);
|
||||||
}
|
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = $this->parseTable($table, $options);
|
$table = $this->parseTable($table, $options);
|
||||||
$joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . $on;
|
$joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . implode(' AND ', $condition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $joinStr;
|
return $joinStr;
|
||||||
|
|||||||
@@ -696,9 +696,6 @@ class Query
|
|||||||
$this->alias([$table => $alias]);
|
$this->alias([$table => $alias]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_array($condition)) {
|
|
||||||
$condition = implode(' AND ', $condition);
|
|
||||||
}
|
|
||||||
$this->options['join'][] = [$table, strtoupper($type), $condition];
|
$this->options['join'][] = [$table, strtoupper($type), $condition];
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
Reference in New Issue
Block a user