当前位置:网站首页>ThinkPHP关联预载入with
ThinkPHP关联预载入with
2022-07-06 22:50:00 【天青色在等你】
关联查询的预查询载入功能,主要解决了N+1次查询的问题,有效提高性能。
$list = User::select([1,2,3]);
foreach($list as $user){
// 获取用户关联的profile模型数据
dump($user->profile);
}
上面这部分代码会执行4次查询
使用关联预载入
$list = User::with(['profile'])->select([1,2,3]);
foreach($list as $user){
// 获取用户关联的profile模型数据
dump($user->profile);
}
如果使用关联预查询功能,就可以变成2次查询(对于一对一关联来说,如果使用withJoin方式只有一次查询),有效提高性能。
$list = User::with(['profile'])->select([1,2,3]);
foreach($list as $user){
// 获取用户关联的profile模型数据
dump($user->profile);
}
主要是因为with查询改为了in条件查询,一次性查出了3条profile模型数据
执行sql如下
边栏推荐
- Using thread class and runnable interface to realize the difference between multithreading
- 01机器学习相关规定
- In depth analysis of kubebuilder
- Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!
- Inventory host list in ansible (I wish you countless flowers and romance)
- [ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
- [Yugong series] go teaching course 005 variables in July 2022
- 【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析
- Tiktok may launch an independent grass planting community platform: will it become the second little red book
- Section 1: (3) logic chip process substrate selection
猜你喜欢

【愚公系列】2022年7月 Go教学课程 005-变量

Programmers go to work fishing, so play high-end!
[email protected]映射关系问题"/>接口间调用为什么要用json、fastjson怎么赋值的、fastjson [email protected]映射关系问题

如何设计 API 接口,实现统一格式返回?

In depth analysis of kubebuilder

Read of shell internal value command

acwing 843. N-queen problem

深入解析Kubebuilder

Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)

Section 1: (3) logic chip process substrate selection
随机推荐
3GPP信道模型路损基础知识
关于01背包个人的一些理解
App embedded H5 --- iPhone soft keyboard blocks input text
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
Weebly移动端网站编辑器 手机浏览新时代
3.基金的类型
[hand torn STL] list
Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
[ArcGIS tutorial] thematic map production - population density distribution map - population density analysis
Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
Windows are not cheap things
How to choose an offer and what factors should be considered
Stm32f103ze+sht30 detection of ambient temperature and humidity (IIC simulation sequence)
STM32F103ZE+SHT30检测环境温度与湿度(IIC模拟时序)
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot microservice code analysis and dialogue experim
Weebly mobile website editor mobile browsing New Era
Techniques d'utilisation de sublime
[736. LISP syntax parsing]
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"