find() doesn't Hydrate object with Single Table Inheritance (SINGLE_TABLE) child object #6414

Closed
opened 2026-01-22 15:32:50 +01:00 by admin · 4 comments
Owner

Originally created by @yosvield on GitHub (Feb 27, 2020).

Bug Report

Q A
BC Break yes/no
Version 2.7.1

Summary

When the object is searched, the child object fields are in null

How to reproduce

i have relationship

/**
 * @ORM\Table(name="comun.person")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="type",type="bigint")
 * @ORM\DiscriminatorMap({"1" = "PersonN", "2" = "PersonJ"})
 */
abstract class Person
{..}

children class

/**
 * @ORM\Table(name="comun.person")
 */
class PersonN extends Person
{...}

When the object is searched, the children class fields are in null

$person=$this->getDoctrine()
            ->getRepository(Person::class)
            ->find(22737);

Expected behavior
find child object

Originally created by @yosvield on GitHub (Feb 27, 2020). ### Bug Report | Q | A |------------ | ------ | BC Break | yes/no | Version | 2.7.1 #### Summary When the object is searched, the child object fields are in null #### How to reproduce i have relationship ```php /** * @ORM\Table(name="comun.person") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="type",type="bigint") * @ORM\DiscriminatorMap({"1" = "PersonN", "2" = "PersonJ"}) */ abstract class Person {..} ``` children class ```php /** * @ORM\Table(name="comun.person") */ class PersonN extends Person {...} ``` When the object is searched, the children class fields are in null ```php $person=$this->getDoctrine() ->getRepository(Person::class) ->find(22737); ``` Expected behavior find child object
admin closed this issue 2026-01-22 15:32:51 +01:00
Author
Owner

@yosvield commented on GitHub (Feb 28, 2020):

I already solved the problem, in the mapping the data type of the discriminatorColumn had it as bigint and in the SimpleObjectHydrator.php class when compared with the discriminatorValue the data type is different. if (isset($cacheKeyInfo['discriminatorValues']) && ! in_array($discrColumnValue, $cacheKeyInfo['discriminatorValues'], true)) {

Fix

/**
* @Orm\Table(name="comun.person")
* @Orm\InheritanceType("SINGLE_TABLE")
* @Orm\DiscriminatorColumn(name="type",type="string")
* @Orm\DiscriminatorMap({"1" = "PersonN", "2" = "PersonJ"})
*/
abstract class Person
{..}
@yosvield commented on GitHub (Feb 28, 2020): I already solved the problem, in the mapping the data type of the discriminatorColumn had it as bigint and in the SimpleObjectHydrator.php class when compared with the discriminatorValue the data type is different. ` if (isset($cacheKeyInfo['discriminatorValues']) && ! in_array($discrColumnValue, $cacheKeyInfo['discriminatorValues'], true)) {` Fix > ``` /** * @Orm\Table(name="comun.person") * @Orm\InheritanceType("SINGLE_TABLE") * @Orm\DiscriminatorColumn(name="type",type="string") * @Orm\DiscriminatorMap({"1" = "PersonN", "2" = "PersonJ"}) */ abstract class Person {..} ```
Author
Owner

@beberlei commented on GitHub (Feb 29, 2020):

@yosvield the problem is really that bigints must be treated as strings, so you can keep the mapping, but your code must be:

$person = $this->getDoctrine()
            ->getRepository(Person::class)
            ->find("22737");

That can be a bit confusing at times

@beberlei commented on GitHub (Feb 29, 2020): @yosvield the problem is really that bigints must be treated as strings, so you can keep the mapping, but your code must be: ``` $person = $this->getDoctrine() ->getRepository(Person::class) ->find("22737"); ``` That can be a bit confusing at times
Author
Owner

@Russellmd commented on GitHub (Mar 2, 2020):

@beberlei is it mandatory to have @DiscriminatorColumn as string type? I found similar issue today, after upgrade (Symfony + Doctrine).

In my case I use Class Table Inheritance ( InheritanceType("JOINED") ), DiscriminatorColumn of type integer. The issue is that my object's fields from joined table are not initialized. Only if I change type for DiscriminatorColumn to string it works as expected.

@Russellmd commented on GitHub (Mar 2, 2020): @beberlei is it mandatory to have @DiscriminatorColumn as string type? I found similar issue today, after upgrade (Symfony + Doctrine). In my case I use Class Table Inheritance ( InheritanceType("JOINED") ), DiscriminatorColumn of type integer. The issue is that my object's fields from joined table are not initialized. Only if I change type for DiscriminatorColumn to string it works as expected.
Author
Owner

@beberlei commented on GitHub (Mar 2, 2020):

@Russellmd i don't know to be honest

@beberlei commented on GitHub (Mar 2, 2020): @Russellmd i don't know to be honest
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6414