You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's normal : when you use QueryBuilder, UnitOfWork register all you show in your screen. But it doens't register the hydrated object, as it's the hydrator who do that.
If you don't want to insert / update read only hydrated entities, you need to manualy register steevanb\DoctrineReadOnlyHydrator\EventSubscriber\ReadOnlySubscriber in Doctrine EventManager, and you don't do that in your snippet.
That's automaticaly done with you use Symfony Bundle.
So, in case you don't need to modify your entity, you want to be really faster, or just retrieve data stored in your database, you can use SimpleObjectHydrator or ReadOnlyHydrator.
This hydrated entities can't be persisted / flushed, because they are not registered in UnitOfwork to be faster.
I ended up going a different route that did not use these hydrators, but my overall goal was to get a quickly hydrated entity out of the database without it being registered to the unit of work.
I set up a basic prototype to see if this package would help solve a problem I am working on.
The code I have is very basic:
bootstrap.php
index.php
After I run
getResult()
through the query, my entity manager unit of work is in this state:To test my theory, I clear the entity manager, mutate the read only entity, merge it back into the entity manager to flush it.
The result is an updated record with
ASDF
as a user name in the database.composer.json
The text was updated successfully, but these errors were encountered: