主义正常vs提取加入 [英] Doctrine Regular vs Fetch join
问题描述
//常规
$ 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();
获取加入的目的是什么?如果我选择你,一个
为什么我只是得到用户
( $ users = $ query - >的getResult();
)?如果我使用常规连接,我可以使用 $ user-> getAddresses()
访问相关对象?
我认为文档描述很好。如果您使用提取连接,相关实体将包含在水合结果中。否则,他们不会,如果您尝试访问它们将触发另一个查询以获取信息。
这只是一个问题,应包含在结果中。
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();
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?
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.
这篇关于主义正常vs提取加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!