mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
Model类增加全局查询范围定义 改进Query类
This commit is contained in:
@@ -964,7 +964,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
} else {
|
} else {
|
||||||
$query->name($this->name);
|
$query->name($this->name);
|
||||||
}
|
}
|
||||||
|
// 全局作用域
|
||||||
|
if (method_exists($this, 'base')) {
|
||||||
|
call_user_func_array([$this, 'base'], [ & $query]);
|
||||||
|
}
|
||||||
self::$links[$model] = $query;
|
self::$links[$model] = $query;
|
||||||
}
|
}
|
||||||
// 返回当前模型的数据库查询对象
|
// 返回当前模型的数据库查询对象
|
||||||
|
|||||||
@@ -1437,7 +1437,6 @@ class Query
|
|||||||
} else {
|
} else {
|
||||||
$where[$key] = strpos($data, ',') ? ['IN', $data] : $data;
|
$where[$key] = strpos($data, ',') ? ['IN', $data] : $data;
|
||||||
}
|
}
|
||||||
$options['where']['AND'] = $where;
|
|
||||||
} elseif (is_array($pk) && is_array($data) && !empty($data)) {
|
} elseif (is_array($pk) && is_array($data) && !empty($data)) {
|
||||||
// 根据复合主键查询
|
// 根据复合主键查询
|
||||||
foreach ($pk as $key) {
|
foreach ($pk as $key) {
|
||||||
@@ -1448,8 +1447,15 @@ class Query
|
|||||||
throw new Exception('miss complex primary data');
|
throw new Exception('miss complex primary data');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($where)) {
|
||||||
|
if (isset($options['where']['AND'])) {
|
||||||
|
$options['where']['AND'] = array_merge($options['where']['AND'], $where);
|
||||||
|
} else {
|
||||||
$options['where']['AND'] = $where;
|
$options['where']['AND'] = $where;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1590,7 +1596,7 @@ class Query
|
|||||||
if (false === $data) {
|
if (false === $data) {
|
||||||
// 用于子查询 不查询只返回SQL
|
// 用于子查询 不查询只返回SQL
|
||||||
$options['fetch_sql'] = true;
|
$options['fetch_sql'] = true;
|
||||||
} elseif (empty($options['where']) && !empty($data)) {
|
} elseif (!empty($data)) {
|
||||||
// 主键条件分析
|
// 主键条件分析
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
}
|
}
|
||||||
@@ -1670,7 +1676,7 @@ class Query
|
|||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
|
|
||||||
if (empty($options['where']) && (!empty($data) || 0 == $data)) {
|
if (!empty($data) || 0 == $data) {
|
||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
}
|
}
|
||||||
@@ -1798,7 +1804,7 @@ class Query
|
|||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
|
|
||||||
if (empty($options['where']) && !empty($data)) {
|
if (!empty($data)) {
|
||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user