公共字段如何“打破延迟加载"?在教义 2 中?

2022-01-03 00:00:00 php doctrine-orm

当我运行 doctrine orm:validate-schema 时,它会弹出一堆关于我的映射列是公开的并且没有使用 getter/setter 方法来包装它们的警告.它说他们打破延迟加载".我可以理解如何将 关联集合 设为公开可能会出现问题(我确实将这些设为私有并包装了它们),但是对于对象上的字段来说,这如何成为问题?据我所知,字段已全部加载.

When I run doctrine orm:validate-schema, it pops up a bunch of warnings about my mapped columns being public and not using getter/setter methods to wrap them. It says that they "break lazy loading". I can understand how making associated collections public could be problematic (I do make these private and wrap them), but how is this an issue for fields on the object? Fields are loaded in full, to my knowledge.

推荐答案

尽管我肯定不是 Doctrine2 专家,但我会尝试一下.

从我的(有限的)使用和测试来看,Doctrine 可能会为您提供一个相关的对象而无需加载该对象的数据.那时公共属性将破坏延迟加载.

From my (limited) usage and testing it seems Doctrine may give you a related object without loading the data for that object. At that point public properties will break lazy loading.

Doctrine 是在请求​​持久化数据时延迟加载,而不是在请求包含持久化数据的对象时.

Doctrine is lazy loading at the point where the persisted data is requested, not when the object that contains persisted data is requested.

更新:我查看了 实际代理代码 看来我原来的理解大多是正确的.在调用对象的方法之前,代理对象不会加载自身.因此,对公共属性的任何请求都不会加载数据.

Update: I took a look at the actual proxy code and it seems my original understanding was mostly correct. The proxy object doesn't load itself until a method of the object is called. So any request to a public property would not load the data.

相关文章