mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进模型对象直接缓存的问题
This commit is contained in:
@@ -32,7 +32,7 @@ use think\model\relation\MorphTo;
|
|||||||
*/
|
*/
|
||||||
abstract class Model implements \JsonSerializable, \ArrayAccess
|
abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||||
{
|
{
|
||||||
// 数据库对象池
|
// 数据库查询对象池
|
||||||
protected static $links = [];
|
protected static $links = [];
|
||||||
// 数据库配置
|
// 数据库配置
|
||||||
protected $connection = [];
|
protected $connection = [];
|
||||||
@@ -40,7 +40,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
protected $parent;
|
protected $parent;
|
||||||
// 数据库查询对象
|
// 数据库查询对象
|
||||||
protected $query;
|
protected $query;
|
||||||
protected $queryObj;
|
|
||||||
// 当前模型名称
|
// 当前模型名称
|
||||||
protected $name;
|
protected $name;
|
||||||
// 数据表名称
|
// 数据表名称
|
||||||
@@ -199,18 +198,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function getQuery($buildNewQuery = false)
|
public function getQuery($buildNewQuery = false)
|
||||||
{
|
{
|
||||||
if (!$buildNewQuery && $this->queryObj) {
|
if ($buildNewQuery) {
|
||||||
return $this->queryObj;
|
return $this->buildQuery();
|
||||||
} else {
|
} elseif (!isset(self::$links[$this->class])) {
|
||||||
// 创建模型查询对象
|
// 创建模型查询对象
|
||||||
$query = $this->buildQuery();
|
self::$links[$this->class] = $this->buildQuery();
|
||||||
|
|
||||||
if (!$buildNewQuery) {
|
|
||||||
$this->queryObj = $query;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return self::$links[$this->class];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ trait SoftDelete
|
|||||||
*/
|
*/
|
||||||
protected function getDeleteTimeField($read = false)
|
protected function getDeleteTimeField($read = false)
|
||||||
{
|
{
|
||||||
$field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time';
|
$field = property_exists($this, 'deleteTime') && isset($this->deleteTime) ? $this->deleteTime : 'delete_time';
|
||||||
if (!strpos($field, '.')) {
|
if (!strpos($field, '.')) {
|
||||||
$field = '__TABLE__.' . $field;
|
$field = '__TABLE__.' . $field;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user