如何防止Doctrine延迟加载一对一的关系ip? [英] How to prevent Doctrine from lazy loading one to one relationsip?

查看:11
本文介绍了如何防止Doctrine延迟加载一对一的关系ip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您遇到类似问题本主题 你会感兴趣

If you're having similar issues This Topic will be of interest to you

我有 User 和 UserSettings 一对一的双向关系.看来,即使我没有在我的页面中使用任何 UserSettings 值,原则还是会延迟加载它.

I have User and UserSettings with one to one bidirectional relationship. It appears that even if i do not use any UserSettings values in my page, doctrine lazy loads it anyways.

这是预期的行为吗?为什么即使我没有在我的页面中使用 Doctrine 获取这些数据?如果我无法阻止它,则每次检索用户对象时都必须将此 UserSettings 加入 User ,但这是不必要的.

Is this expected behavior? Why is Doctrine fetching this data even though I'm not using it in my page? If I'm unable to stop it, I would have to join this UserSettings to User every time I retrieve user object, but this is so unnecessary.

我能做些什么来防止这种情况发生?

What can I do to prevent this from happening?

加载数据的代码:

->createQuery('SELECT p, u, s FROM TestPostBundle:Post p LEFT JOIN p.user u LEFT JOIN p.sub s WHERE p.id IN (:ids)')
->setParameter('ids', $ids)
->getResult();

在树枝中,我遍历帖子并显示帖子数据和相关用户,但我从不请求任何 UserSettings 变量,我根本没有访问它们.

The in twig I loop through posts and display Post data and associated user, but I never request any UserSettings variables, I'm not accessing them at all.

推荐答案

我也遇到了同样的问题.似乎从反面学说查询时也查询拥有方.请参阅此讨论.

I also faced same problem. It seems that when querying from inverse side doctrine also queries the owning side. See this discussion.

这篇关于如何防止Doctrine延迟加载一对一的关系ip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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