改进关联模型

This commit is contained in:
thinkphp
2017-04-01 16:13:44 +08:00
parent 2ebf07ba16
commit d3be47e269
7 changed files with 39 additions and 13 deletions

View File

@@ -50,7 +50,13 @@ class BelongsTo extends OneToOne
if ($closure) {
call_user_func_array($closure, [ & $this->query]);
}
return $this->query->where($this->localKey, $this->parent->$foreignKey)->relation($subRelation)->find();
$relationModel = $this->query
->where($this->localKey, $this->parent->$foreignKey)
->relation($subRelation)
->find();
$relationModel->setParent(clone $this->parent);
return $relationModel;
}
/**