Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 使用';块';连同';与';关于Laravel查询生成器_Database_Performance_Laravel_Laravel 5 - Fatal编程技术网

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();