Doctrine Regular vs Fetch join [英] Doctrine Regular vs Fetch join

查看:20
本文介绍了Doctrine Regular vs Fetch join的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在原则上,regular 和 fetch join 之间的区别是什么?我不只是通过阅读 文档.

in doctrine, whats the diff between regular and fetch join? i dont get it just by reading the docs.

// regular
$query = $em->createQuery("SELECT u FROM User u JOIN u.address a WHERE a.city = 'Berlin'");
$users = $query->getResult();

// fetch
$query = $em->createQuery("SELECT u, a FROM User u JOIN u.address a WHERE a.city = 'Berlin'");
$users = $query->getResult();

fetch join 的目的是什么?如果我 select u, a 为什么我只是得到 users ($users = $query->getResult();)?如果我使用常规连接,我可能可以使用 $user->getAddresses() 来访问相关对象?

whats the purpose of fetch join? if i select u, a why am i just getting users ($users = $query->getResult();)? if i use a regular join, i can probably use $user->getAddresses() to access the related objects?

推荐答案

我认为文档描述得很好.如果您使用 fetch join,相关实体将包含在水合结果中.否则它们不会,如果您随后尝试访问它们,它将触发另一个查询以获取信息.

I think the docs describe it pretty well. If you use a fetch join, the related entities will be included in the hydrated result. Otherwise they won't, and if you then try to access them it'll fire off another query to get the information.

这只是是否应将其包含在结果中的问题.

It's simply a matter of whether or not it should be included in the results.

这篇关于Doctrine Regular vs Fetch join的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆