Query类的relation方法和with方法一样支持使用闭包进行自定义关联查询

This commit is contained in:
thinkphp
2017-01-16 10:31:03 +08:00
parent ba7232b678
commit d5d5314f2e
8 changed files with 41 additions and 10 deletions

View File

@@ -38,13 +38,16 @@ class HasOne extends OneToOne
/**
* 延迟获取关联数据
* @param \Closure $closure 闭包查询条件
* @access public
*/
public function getRelation()
public function getRelation($colsure = null)
{
// 执行关联定义方法
$localKey = $this->localKey;
if ($closure) {
call_user_func_array($closure, [ & $this->query]);
}
// 判断关联类型执行查询
return $this->query->where($this->foreignKey, $this->parent->$localKey)->find();
}