Subclasses of subclasses don't hydrate #5877

Closed
opened 2026-01-22 15:20:57 +01:00 by admin · 2 comments
Owner

Originally created by @technetium on GitHub (Feb 8, 2018).

When I try to get all my entities of a subclass. The subclassed entities of those entities are null.

To reproduce:

Classes definitions:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="customerDiscriminator",type="string")
 */
class Level1
{
    /* class properties and methods */
}

/**
 * @ORM\Entity()
 */
class Level2 extends Level1
{
    /* class properties and methods */
}

/**
 * @ORM\Entity()
 */
class Level3 extends Level2
{
    /* class properties and methods */
}

Expected result:

$this->getEntityManager(Level2:class)->getRepository(Level2:class)->findAll();
Should return an array of all Level2 and Level3 objects

Actual result:
Returns an array if all Level2 objects, and null records for all Level3 objects

Solution:
Check in Doctrine/ORM/Internal/Hydration/AbstractHydrator->gatherRowData() not only if the discriminator value in the database is not equal to the value of the discriminator of the class, but also not equal to the values of the subclasses. See my pull request #7051
.

I did not include any test with it. Can someone help me to create tests for this?

Originally created by @technetium on GitHub (Feb 8, 2018). When I try to get all my entities of a subclass. The subclassed entities of those entities are null. To reproduce: Classes definitions: ``` use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity() * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="customerDiscriminator",type="string") */ class Level1 { /* class properties and methods */ } /** * @ORM\Entity() */ class Level2 extends Level1 { /* class properties and methods */ } /** * @ORM\Entity() */ class Level3 extends Level2 { /* class properties and methods */ } ``` Expected result: `$this->getEntityManager(Level2:class)->getRepository(Level2:class)->findAll();` Should return an array of all Level2 and Level3 objects Actual result: Returns an array if all Level2 objects, and null records for all Level3 objects Solution: Check in Doctrine/ORM/Internal/Hydration/AbstractHydrator->gatherRowData() not only if the discriminator value in the database is not equal to the value of the discriminator of the class, but also not equal to the values of the subclasses. See my pull request #7051 . I did not include any test with it. Can someone help me to create tests for this?
admin added the BugDuplicate labels 2026-01-22 15:20:57 +01:00
admin closed this issue 2026-01-22 15:20:58 +01:00
Author
Owner

@holtkamp commented on GitHub (Feb 8, 2018):

Might be related to https://github.com/doctrine/doctrine2/issues/6937, which got a test case included

@holtkamp commented on GitHub (Feb 8, 2018): Might be related to https://github.com/doctrine/doctrine2/issues/6937, which got a test case included
Author
Owner

@beberlei commented on GitHub (Dec 7, 2020):

Fixed in https://github.com/doctrine/orm/pull/6988

@beberlei commented on GitHub (Dec 7, 2020): Fixed in https://github.com/doctrine/orm/pull/6988
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5877