mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Model类的useGlobalScope方法调用后的全局影响
This commit is contained in:
@@ -1188,7 +1188,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
public static function useGlobalScope($use)
|
public static function useGlobalScope($use)
|
||||||
{
|
{
|
||||||
$model = new static();
|
$model = new static();
|
||||||
self::$db = $model->db($use);
|
static::$db = $model->db($use);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1461,9 +1461,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
if (isset(static::$db)) {
|
if (isset(static::$db)) {
|
||||||
$query = static::$db;
|
$query = static::$db;
|
||||||
|
static::$db = null;
|
||||||
} else {
|
} else {
|
||||||
$query = $this->db();
|
$query = $this->db();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method_exists($this, 'scope' . $method)) {
|
if (method_exists($this, 'scope' . $method)) {
|
||||||
// 动态调用命名范围
|
// 动态调用命名范围
|
||||||
$method = 'scope' . $method;
|
$method = 'scope' . $method;
|
||||||
@@ -1479,6 +1481,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
{
|
{
|
||||||
if (isset(static::$db)) {
|
if (isset(static::$db)) {
|
||||||
$query = static::$db;
|
$query = static::$db;
|
||||||
|
static::$db = null;
|
||||||
} else {
|
} else {
|
||||||
$query = (new static())->db();
|
$query = (new static())->db();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user