Discriminator Bug: lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php #6442

Open
opened 2026-01-22 15:33:23 +01:00 by admin · 1 comment
Owner

Originally created by @AndreyMashukov on GitHub (Apr 10, 2020).

Bug Report

Q A
BC Break ???
Version 2.6.3

Summary

lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:441

$targetClass = $this->_metadataCache[$relation['targetEntity']];

Current behavior

so, if you have discriminator entity Contact (abstract class) and two children: Realtor and Owner for example, and use targetEntity=Contact in the some class, for example it is Advert, it will crush when you will try to hydrate it as object via ResultSetMappingBuilder

How to reproduce

Set super class as target entity and try to get result with ObjectHydrator.php

Expected behavior

ObjectHydrator will return correct Contact's child

How to fix?

just fix 441 line

$targetClass = $this->_metadataCache[$relation['targetEntity']] ?? $this->_metadataCache[$entityName];
Originally created by @AndreyMashukov on GitHub (Apr 10, 2020). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | ??? | Version | 2.6.3 #### Summary lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:441 ```php $targetClass = $this->_metadataCache[$relation['targetEntity']]; ``` #### Current behavior so, if you have discriminator entity `Contact` (abstract class) and two children: `Realtor` and `Owner` for example, and use `targetEntity=Contact` in the some class, for example it is `Advert`, it will crush when you will try to hydrate it as object via `ResultSetMappingBuilder` #### How to reproduce Set super class as target entity and try to get result with ObjectHydrator.php #### Expected behavior ObjectHydrator will return correct `Contact`'s child #### How to fix? just fix 441 line ```php $targetClass = $this->_metadataCache[$relation['targetEntity']] ?? $this->_metadataCache[$entityName]; ```
Author
Owner

@AndreyMashukov commented on GitHub (Apr 10, 2020):

Снимок экрана 2020-04-10 в 23 32 09
@AndreyMashukov commented on GitHub (Apr 10, 2020): <img width="926" alt="Снимок экрана 2020-04-10 в 23 32 09" src="https://user-images.githubusercontent.com/24682497/79021182-888b8a80-7b83-11ea-8427-5f193dd05dd1.png">
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6442