-
-
Notifications
You must be signed in to change notification settings - Fork 454
Undocumented doctrine.orm.enable_lazy_ghost_objects
#1651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's a relatively new feature depending on Symfony >=6.2 and ORM >=2.14 and the ORM docs are also missing this feature. Do you like to add the missing docs in a pull request? |
This is an opt-in for the new way to manage proxies in the ORM (which requires symfony/var-exporter 6.2+). As the code should be working fine now, I see no reason to set it to |
Sadly it's not safe to keep it set to false when using readonly public properties in entities: #9432 |
Enabling this setting is the future. Not setting it to |
Then it should have been documented in UPGRADE.md doc |
Whoa... not so fast. I constantly run into issues where a ManyToOne relation entity on the One side is not fully hydrated when this option is set to true. To be safe I have to always set it to false. Short example: You have an entity Foo that has a ManyToOne relation with entity Bar: #[ORM\ManyToOne(targetEntity: Bar::class)]
#[ORM\JoinColumn(nullable: false)]
private ?Bar $bar = null; Entity Bar has a Doctrine listener that auto populates some non-persistent fields on PostLoad(). Entity Foo database record is auto read into a Controller change method ( If you access the non-persistent field(s) in the Controller method with The only time it fires with the flag set to true is when you specify fetch: "EAGER" on the relation. If you set |
@gnito-org can you share a reproducer for that ? |
Further investigation revealed that my issue is not related to the The problem occurs when you access a virtual property of a LAZY or EXTRA_LAZY loaded entity and you do not also access a persisted property of the entity. In this case the doctrine postLoad listener does not fire. The listener does fire in this scenario if it is an EAGER loaded entity. |
I published the replicator that I was using to debug the issue here: |
Well, the listener fires when the persistent properties are loaded (as that exactly what With EAGER as strategy, Doctrine forces the loading of entities when they are registered in the unit of work, so the loading happen. With any lazy strategy, the loading is delayed.
The drawback of the new approach is indeed that code that does not read any persistent property can indeed not rely anymore on the fact that the entity is loaded (and so that |
Thank you for the detail explanation. I will just use an eager fetch. Problem solved. |
So, still no documentation? I'm currently on Symfony 5.4. I see a deprecation notice that I need to set |
@craigh please open a dedicated issue with the error message you get. This issue is about lacking the documentation, not about things being broken (and so it would be closed once the PR adding the documentation gets merged). |
It would be nice to add the ability to install The problems are as follows (version 7.2):
However, the behavior of this proxy is currently hardcoded inside DocumentManager and/or EntityManager, so I have to work around the problem by making patches in the vendor, overwriting the existing |
doctrine/orm does not have a public extension point for its proxy implementation. As long as that's the case, the bundle cannot offer you to configure the usage of such extension point. |
I understand, that's why I suggest adding it or implementing another implementation via |
There is always room for more contributors, also doctrine/orm#11853 if you want to follow something there is happening in orm. |
I don't understand the point of this proxy factory yet, since my integration tests show that the number of requests to the database does not change with its presence (including one2one/one2many relations) |
I'm currently upgrading a big project's flex recipes and one of the dependencies I just upgraded was this one.
Now I'm facing
doctrine.orm.enable_lazy_ghost_objects
(see #1568), and wanted to research about possible implications on my project. Sadly, it's undocumented. If you're going to ask, yes on both #1605.I'm pretty sure this is safe in my project, but I'm wondering: could we please documented what this flag is doing? I'm pretty sure what it's purpose is, but I might not be the only (experienced Symfony) developer ;-)
The text was updated successfully, but these errors were encountered: