Updating one to one doctrine2
I avoid bi-directional one-to-one altogether to avoid this performance trap.Doctrine's lazy loading feature is an amazing time-saver for prototyping, but when growing an application it can be a huge performance killer.This can be very inconvenient when it triggers additional queries and entity creation that is not needed in a request.This mistake slips in easily when using inheritance, because you don't see it in the mappings, for example in this association where you need to know operation we see one additional query for each registration entity.See the documentation on caching for details on setup for different caching backends.One of the Doctrine's most powerful features is the Doctrine Query Language (DQL), but you should know about the cases where it can cause performance problems.You should not rely on this behavior, because it is dependent on how you query the entity.In larger applications with many developers this performance trap is often a problem, because it is so hard to spot in code.
Consider this query for both companies and its employees: -clause, causing Doctrine to load both Company and every Employee entity together.
This allows to aggregate all writes (INSERT, UPDATE, DELETE) into one single transaction, which is executed when flush is called.
Looking up data is not a responsibility of the Entity Manager: it’s a repository concern.
An Active record object inherits all the facilities to retrieve, update and save itself.
The Data Mapper pattern has a separate mapper class to manage object persistence.
Search for updating one to one doctrine2:
But using any ORM requires careful consideration with regards to performance, especially the critical paths in your application that you want to be very fast.