关联定义增加selfRelation方法用于设置是否自关联

This commit is contained in:
thinkphp
2018-01-05 17:55:29 +08:00
parent ea2ce8f8de
commit df1c05a988
2 changed files with 25 additions and 1 deletions

View File

@@ -612,7 +612,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/
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;
} else {
// 首先获取关联数据