mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
关联定义增加selfRelation方法用于设置是否自关联
This commit is contained in:
@@ -612,7 +612,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
protected function getRelationData(Relation $modelRelation)
|
protected function getRelationData(Relation $modelRelation)
|
||||||
{
|
{
|
||||||
if ($this->parent && $modelRelation->getModel() == $this->parent) {
|
if ($this->parent && !$modelRelation->isSelfRelation() && get_class($modelRelation->getModel()) == get_class($this->parent)) {
|
||||||
$value = $this->parent;
|
$value = $this->parent;
|
||||||
} else {
|
} else {
|
||||||
// 首先获取关联数据
|
// 首先获取关联数据
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ abstract class Relation
|
|||||||
protected $localKey;
|
protected $localKey;
|
||||||
// 基础查询
|
// 基础查询
|
||||||
protected $baseQuery;
|
protected $baseQuery;
|
||||||
|
// 是否为自关联
|
||||||
|
protected $selfRelation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取关联的所属模型
|
* 获取关联的所属模型
|
||||||
@@ -66,6 +68,28 @@ abstract class Relation
|
|||||||
return $this->query;
|
return $this->query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前关联为自关联
|
||||||
|
* @access public
|
||||||
|
* @param bool $self 是否自关联
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function selfRelation($self = true)
|
||||||
|
{
|
||||||
|
$this->selfRelation = $self;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前关联是否为自关联
|
||||||
|
* @access public
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isSelfRelation()
|
||||||
|
{
|
||||||
|
return $this->selfRelation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装关联数据集
|
* 封装关联数据集
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user