mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Query类的view方法和join方法 支持使用不带前缀的表名
This commit is contained in:
@@ -669,7 +669,11 @@ class Query
|
|||||||
$table = array_shift($join);
|
$table = array_shift($join);
|
||||||
}
|
}
|
||||||
} else {
|
} 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, ')')) {
|
if (strpos($table, ' ') && !strpos($table, ')')) {
|
||||||
list($table, $alias) = explode(' ', $table);
|
list($table, $alias) = explode(' ', $table);
|
||||||
$table = [$table => $alias];
|
$table = [$table => $alias];
|
||||||
@@ -763,13 +767,17 @@ class Query
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
$prefix = $this->prefix;
|
||||||
if (is_array($join)) {
|
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 {
|
} else {
|
||||||
$alias = $join;
|
$alias = $join;
|
||||||
}
|
}
|
||||||
$table = !empty($table) ? $table : $this->getTable($join);
|
$table = isset($table) ? [$table => $alias] : $alias;
|
||||||
if (true === $field) {
|
if (true === $field) {
|
||||||
$fields = $alias . '.*';
|
$fields = $alias . '.*';
|
||||||
} else {
|
} else {
|
||||||
@@ -793,9 +801,9 @@ class Query
|
|||||||
}
|
}
|
||||||
$this->field($fields);
|
$this->field($fields);
|
||||||
if ($on) {
|
if ($on) {
|
||||||
$this->join($table . ' ' . $alias, $on, $type);
|
$this->join($table, $on, $type);
|
||||||
} else {
|
} else {
|
||||||
$this->table($table . ' ' . $alias);
|
$this->table($table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
Reference in New Issue
Block a user