在教义2中,可以在运行时改变提取模式(渴望/懒惰等)? [英] In Doctrine 2 can the Fetch Mode (Eager/Lazy etc.) be changed at runtime?

查看:92
本文介绍了在教义2中,可以在运行时改变提取模式(渴望/懒惰等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的映射没有声明在inㄧin in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in in我的YAML-所以他们使用默认(懒加载)。



目前,热切加载的唯一方法是手动构建DQL - 我需要更新每个时间我添加一个新的实体。



理想情况下,我只是加载根实体,强制加载所有关联的对象。有没有什么办法可以做到这一点?



如果不是为什么(有没有一个原因超出它是一个未实现的功能)?

解决方案

如果要使用内置的存储库方法(find(),findAll()),那么你可能会运气不好,除非你设置好了,您的注释。



您可能希望在某些自定义存储库的方法中使用查询构建器(或原始DQL)来强制加载您想要的位置。是的,您必须在添加实体时更新该方法,但至少您将永远知道在延迟/加载加载方面发生了什么,您只需要将其全部保留在一个位置。 p>

我认为没有一些$ eagerLoad标志来找到()等的原因是因为这些是简单任务的便利方法。如果你想添加这样一个标志,你将很快进入你想要限制深度递归加载的情况。你也可能不得不开始担心循环引用(例如任何双向关联)。


I have entities which I would like to eagerly load , and on other ocassions lazy (or even extra lazy) load.

My mappings have no fetch mode declared in my YAML- so they use the default (lazy loading).

Currently the only way to eagerly load is to by constructing the DQL manually - and I need to update this every time I add a new entity.

Ideally I would just load the root entity and the force eager loading all the associated objects. Is there any way I can do this?

If not why (is there a reason beyond it being an unimplemented feature)?

解决方案

If you want to use built-in repository methods (find(), findAll()), you're probably out of luck unless you set things to eagerly load in your annotations.

You'll probably want to use the query builder (or raw DQL) in some custom repository's method to force eager loading where you want it. Yes, you'll have to update that method as you add entities, but at least you'll always know what's going on in regards to lazy/eager loading, and you'll only need to maintain it all in one place.

I suppose the reason there's not some $eagerLoad flag to find(), etc, is because those are convenience methods for simple tasks. If you wanted to add such a flag, you'd have quickly get into situations where you'd want to limit recursive eager loading by depth. You'd also probably have to start worrying about cyclical references (any bidirectional association, for instance).

这篇关于在教义2中,可以在运行时改变提取模式(渴望/懒惰等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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