php - 如何使用嵌套的项目列表来减少数据库查询的数量
问题描述
解决方案
您也必须急切地加载子子项:
$columns = ['id', 'parent_id', 'title'];
$result = $this->startConditions()
->select($columns)
->with(['children:id,title,parent_id', 'children.children:id,title'])
->get();
return $result;
考虑本文中的以下示例:https ://laravel-news.com/eloquent-eager-loading
$posts = App\Post::with('author.profile')->get();
$posts->map(function ($post) {
return $post->author->profile;
});
在这里你可以看到他们使用点符号来获取深层关系with()
推荐阅读
- jupyter-notebook - 如何隐藏 jupyter notebook 中的特定单元格?
- grafana - 如何在 2.0 版本中连接到 influxDB
- flutter - 灵活在 Toggle Button Widget Flutter 中不起作用
- php - JSON 解析错误:警告:尝试读取数组上的属性
- sqlite - 在非常大的 sqlite 表上创建索引会出现“已终止”错误
- drake - Drake中如何将多体植物的广义坐标向量映射到刚体树的广义坐标向量?
- c - malloc 将分配和返回多少字节?
- reactjs - 如何在本机反应中全局处理错误?
- java - 使用来自 apache sshd 的 ssh 设置 ssh 密钥以与 jgit 一起使用
- or-tools - OR-Tools:一个 IntVar 是一个 IntVar 减去 Java 中的另一个 IntVar?