主义正常vs提取加入 [英] Doctrine Regular vs Fetch join

查看:127
本文介绍了主义正常vs提取加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在理论中,常规和获取加入之间的差异是什么?我不会通过阅读 docs

  //常规
$ 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屋!

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