mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进关联查询的全局命名范围查询
This commit is contained in:
@@ -1341,9 +1341,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
{
|
||||
$query = $this->db();
|
||||
// 全局作用域
|
||||
if ($this->useGlobalScope && method_exists($this, 'base')) {
|
||||
call_user_func_array([$this, 'base'], [ & $query]);
|
||||
}
|
||||
$this->baseQuery($query);
|
||||
if (method_exists($this, 'scope' . $method)) {
|
||||
// 动态调用命名范围
|
||||
$method = 'scope' . $method;
|
||||
@@ -1360,12 +1358,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$query = self::getDb();
|
||||
$model = new static();
|
||||
// 全局作用域
|
||||
if ($model->useGlobalScope && method_exists($model, 'base')) {
|
||||
call_user_func_array([$model, 'base'], [ & $query]);
|
||||
}
|
||||
$model->baseQuery($query);
|
||||
return call_user_func_array([$query, $method], $params);
|
||||
}
|
||||
|
||||
public function baseQuery(&$query)
|
||||
{
|
||||
// 全局作用域
|
||||
if ($this->useGlobalScope && method_exists($this, 'base')) {
|
||||
call_user_func_array([$this, 'base'], [ & $query]);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getDb()
|
||||
{
|
||||
$model = get_called_class();
|
||||
|
||||
@@ -661,6 +661,9 @@ class Relation
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if ($this->query) {
|
||||
$class = new $this->model;
|
||||
// 全局作用域
|
||||
$class->baseQuery($this->query);
|
||||
switch ($this->type) {
|
||||
case self::HAS_MANY:
|
||||
if (isset($this->where)) {
|
||||
|
||||
Reference in New Issue
Block a user