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

@@ -1282,14 +1282,18 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
}
foreach ($relations as $key => $relation) {
$closure = null;
$subRelation = '';
$closure = null;
if ($relation instanceof \Closure) {
// 支持闭包查询过滤关联条件
$closure = $relation;
$relation = $key;
}
if (strpos($relation, '.')) {
list($relation, $subRelation) = explode('.', $relation);
}
$method = Loader::parseName($relation, 1, false);
$this->data[$relation] = $this->$method()->getRelation($closure);
$this->data[$relation] = $this->$method()->getRelation($subRelation, $closure);
}
return $this;
}