Deprecate: Load *-to-one entity with subClasses #7071

Closed
opened 2026-01-22 15:44:08 +01:00 by admin · 0 comments
Owner

Originally created by @dmitryuk on GitHub (Nov 18, 2022).

BC Break Report

Q A
BC Break yes
Version 2.0.0

Summary

UnitOfWork has a way to hydrate *-to-one relation entity, that has subClasses (inherited):

 case $targetClass->subClasses:
          // If it might be a subtype, it can not be lazy. There isn't even
          // a way to solve this with deferred eager loading, which means putting
          // an entity with subclasses at a *-to-one location is really bad! (performance-wise)
          $newValue = $this->getEntityPersister($assoc['targetEntity'])->loadOneToOneEntity($assoc, $entity, $associatedId);
          break;

But in my case I received a large performance overhead because my entity has hierarchic structure like parent->parent->parent.
So querying one Entity will execute and hydrate all parents and it was really hard to find reason.

Previous behavior

Large overhead without notice

Current behavior proposal (2.0)

trigger_deprecation if this going on.

Doctrine 3 proposal

Throw an exception

Originally created by @dmitryuk on GitHub (Nov 18, 2022). ### BC Break Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.0.0 #### Summary UnitOfWork [has a way ](https://github.com/doctrine/orm/blob/2.13.x/lib/Doctrine/ORM/UnitOfWork.php#L2871)to hydrate *-to-one relation entity, that has subClasses (inherited): ``` case $targetClass->subClasses: // If it might be a subtype, it can not be lazy. There isn't even // a way to solve this with deferred eager loading, which means putting // an entity with subclasses at a *-to-one location is really bad! (performance-wise) $newValue = $this->getEntityPersister($assoc['targetEntity'])->loadOneToOneEntity($assoc, $entity, $associatedId); break; ``` But in my case I received a large performance overhead because my entity has hierarchic structure like `parent->parent->parent`. So querying one Entity will execute and hydrate all `parent`s and it was really hard to find reason. #### Previous behavior Large overhead without notice #### Current behavior proposal (2.0) `trigger_deprecation` if this going on. #### Doctrine 3 proposal Throw an exception
admin closed this issue 2026-01-22 15:44:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7071