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