Database 使用';块';连同';与';关于Laravel查询生成器
不知道这是否可能。。我试图查询一大组具有如下关系的数据:Database 使用';块';连同';与';关于Laravel查询生成器,database,performance,laravel,laravel-5,Database,Performance,Laravel,Laravel 5,不知道这是否可能。。我试图查询一大组具有如下关系的数据: Parent::with([ 'child' => function($query) { $query->('published', '=', true); $query->with('child.of.child', 'some.other.child'); $query->chunk(400, function($c
Parent::with([
'child' => function($query) {
$query->('published', '=', true);
$query->with('child.of.child', 'some.other.child');
$query->chunk(400, function($childs) {
// how is it now possible to add the $childs to the parent result??
});
}
]);
现在$parent['models']包含包含所有嵌套子关系的树。。。不知道这是否是最聪明的方法,但它目前仍然有效。在查询生成器代码中进行了一些尝试和挖掘之后,我找到了一个解决方案:
$parent = [];
Parent::with(
[
'childs' => function ($query) use (&$parent) {
$query->where('STATUS', '!=', 'DELETED');
$query->with('some.child', 'some.other.child');
$parent['models'] = $query->getParent()
->getModels();
$query->chunk(
400, function ($result) use ($query, &parent) {
$query->match($parent['models'], $result, 'child-relations-name');
});
}
])
->get();