fetch =“EAGER”之间有什么区别?并且获取=“LAZY”在教义中 [英] What is the difference between fetch="EAGER" and fetch="LAZY" in doctrine

查看:116
本文介绍了fetch =“EAGER”之间有什么区别?并且获取=“LAZY”在教义中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Doctrine中的注释@ManyToOne中,fetch =EAGER和fetch =LAZY有什么区别?

What is the difference between fetch="EAGER" and fetch="LAZY" in annotation @ManyToOne in Doctrine ?

/**
 * @ManyToOne(targetEntity="Cart", cascade={"all"}, fetch="EAGER")
 */

/**
 * @ManyToOne(targetEntity="Cart", cascade={"all"}, fetch="LAZY")
 */


推荐答案

简单地说,当你加载一个实体,如果它与一个或多个实体有关联,应该做什么?

To explain it simply, when you are loading an entity and if it has an association with one or more entities, what should doctrine do?

如果关联被标记为EAGER,它将会获取并加载关联的实体。

If the association is marked as EAGER, it will fetch and load the associated entity as well.

如果该关联标记为LAZY,原则将创建代理对象(虚拟对象)来代替实体。只有当您对该关联实体进行第一次调用(如$ cart-> getItems())时,doctrine将从数据库中获取并加载该对象。

If the association is marked as LAZY, doctrine will create proxy objects (dummy objects) in place of the actual entity. Only when you make the first call to that associated entity (like $cart->getItems()), doctrine will fetch and load that object(s) from database.

请参阅: http://docs.doctrine-project.org/en/最新/ reference / advanced-configuration.html#association-proxies

这篇关于fetch =“EAGER”之间有什么区别?并且获取=“LAZY”在教义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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