mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-09-02 05:31:36 +08:00
Query类的relation方法和with方法一样支持使用闭包进行自定义关联查询
This commit is contained in:
@@ -1281,8 +1281,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$relations = explode(',', $relations);
|
||||
}
|
||||
|
||||
foreach ($relations as $relation) {
|
||||
$this->data[$relation] = $this->$relation()->getRelation();
|
||||
foreach ($relations as $key => $relation) {
|
||||
$closure = null;
|
||||
if ($relation instanceof \Closure) {
|
||||
// 支持闭包查询过滤关联条件
|
||||
$closure = $relation;
|
||||
$relation = $key;
|
||||
}
|
||||
$method = Loader::parseName($relation, 1, false);
|
||||
$this->data[$relation] = $this->$method()->getRelation($closure);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user