Query类relation支持嵌套关联

This commit is contained in:
thinkphp
2017-01-16 15:52:21 +08:00
parent 00136a3f4b
commit 47a869f3af
8 changed files with 27 additions and 17 deletions

View File

@@ -38,17 +38,17 @@ class BelongsTo extends OneToOne
/**
* 延迟获取关联数据
* @param string $subRelation 子关联名
* @param \Closure $closure 闭包查询条件
* @access public
*/
public function getRelation($closure = null)
public function getRelation($subRelation = '', $closure = null)
{
$foreignKey = $this->foreignKey;
$localKey = $this->localKey;
if ($closure) {
call_user_func_array($closure, [ & $this->query]);
}
return $this->query->where($localKey, $this->parent->$foreignKey)->find();
return $this->query->where($this->localKey, $this->parent->$foreignKey)->relation($subRelation)->find();
}
/**