fetch="EAGER" 和有什么区别?和 fetch="LAZY"在教义上 [英] What is the difference between fetch="EAGER" and fetch="LAZY" in doctrine

查看:38
本文介绍了fetch="EAGER" 和有什么区别?和 fetch="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")
 */

推荐答案

简单的解释一下,当你加载一个实体时,如果它与一个或多个实体有关联,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)

参考:https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/advanced-configuration.html#association-proxies

这篇关于fetch="EAGER" 和有什么区别?和 fetch="LAZY"在教义上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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