Query支持调用模型的查询范围

This commit is contained in:
yunwuxin
2018-10-08 15:18:54 +08:00
parent aeab3965f2
commit 4a882963d6

View File

@@ -92,6 +92,13 @@ class Query
$name = Loader::parseName(substr($method, 10)); $name = Loader::parseName(substr($method, 10));
$where[$name] = $args[0]; $where[$name] = $args[0];
return $this->where($where)->value($args[1]); return $this->where($where)->value($args[1]);
} elseif ($this->model && method_exists($this->model, 'scope' . $method)) {
// 动态调用命名范围
$method = 'scope' . $method;
array_unshift($args, $this);
call_user_func_array([$this->model, $method], $args);
return $this;
} else { } else {
throw new Exception('method not exist:' . __CLASS__ . '->' . $method); throw new Exception('method not exist:' . __CLASS__ . '->' . $method);
} }