mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进自关联查询多级调用问题
This commit is contained in:
@@ -192,7 +192,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$con = Db::connect($connection);
|
||||
// 设置当前模型 确保查询返回模型对象
|
||||
$queryClass = $this->query ?: $con->getConfig('query');
|
||||
$query = new $queryClass($con, $this->class);
|
||||
$query = new $queryClass($con, $this);
|
||||
|
||||
// 设置当前数据表和模型名
|
||||
if (!empty($this->table)) {
|
||||
@@ -208,6 +208,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的模型实例
|
||||
* @access public
|
||||
* @param array|object $data 数据
|
||||
* @param bool $isUpdate 是否为更新
|
||||
* @param mixed $where 更新条件
|
||||
* @return Model
|
||||
*/
|
||||
public function newInstance($data = [], $isUpdate = false, $where = null)
|
||||
{
|
||||
return (new static($data))->isUpdate($isUpdate, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模型的查询对象
|
||||
* @access public
|
||||
@@ -599,7 +612,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
*/
|
||||
protected function getRelationData(Relation $modelRelation)
|
||||
{
|
||||
if ($this->parent && get_class($this->parent) == $modelRelation->getModel()) {
|
||||
if ($this->parent && $modelRelation->getModel() == $this->parent) {
|
||||
$value = $this->parent;
|
||||
} else {
|
||||
// 首先获取关联数据
|
||||
|
||||
Reference in New Issue
Block a user