当前位置:网站首页>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如下
边栏推荐
- Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
- Ansible overview and module explanation (you just passed today, but yesterday came to your face)
- AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘
- MySQL数据库(基础篇)
- Section 1: (3) logic chip process substrate selection
- In depth analysis of kubebuilder
- JS input and output
- Analysis -- MySQL statement execution process & MySQL architecture
- Basic idea of counting and sorting
- Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
猜你喜欢

Flex layout and usage

Ansible overview and module explanation (you just passed today, but yesterday came to your face)

Section 1: (3) logic chip process substrate selection

动态生成表格

Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str

Weebly移动端网站编辑器 手机浏览新时代
![[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails](/img/e0/04f06d464e77012fbfc919e07cbb66.png)
[Android kotlin collaboration] use coroutinecontext to realize the retry logic after a network request fails

U++4 接口 学习笔记

AttributeError: module ‘torch._ C‘ has no attribute ‘_ cuda_ setDevice‘

Windows are not cheap things
随机推荐
高手勿进!写给初中级程序员以及还在大学修炼的“准程序员”的成长秘籍
What work items do programmers hate most in their daily work?
JS variable plus
2. Overview of securities investment funds
【愚公系列】2022年7月 Go教学课程 005-变量
指针与数组在函数中输入实现逆序输出
3.基金的类型
National meteorological data / rainfall distribution data / solar radiation data /npp net primary productivity data / vegetation coverage data
File upload vulnerability summary
Jetson nano configures pytorch deep learning environment / / to be improved
In depth analysis of kubebuilder
How does vscade use the built-in browser?
如何设计 API 接口,实现统一格式返回?
offer如何选择该考虑哪些因素
动态生成表格
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Introduction to namespace Basics
Two methods of chromosome coordinate sequencing
Weebly mobile website editor mobile browsing New Era
Comparison between thread and runnable in creating threads