问题描述
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")
*/
推荐答案
简单的解释一下,当你加载一个实体时,如果它与一个或多个实体有关联,doctor应该怎么做?
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()
)时,Doctor 才会从数据库中获取并加载该对象.(这是 默认行为)
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. (This is the default Behaviour)
这篇关于fetch="EAGER" 和有什么区别?和 fetch="LAZY"在教义上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!