Getting parent of null #5661

Closed
opened 2026-01-22 15:14:00 +01:00 by admin · 5 comments
Owner

Originally created by @mcanepa on GitHub (Aug 29, 2017).

Originally assigned to: @Ocramius on GitHub.

I have an entity "MyEntity" like

@ORM\InheritanceType("SINGLE_TABLE")
@ORM\DiscriminatorColumn(name="type", type="string")

With this attribute that serves as reference to the parent

/**
 * @ORM\OneToOne(targetEntity="MyEntity")
 */
protected $parent;

In the database, data like this is stored

+----+-----------+-------+---------+
| id | parent_id | name  |  type   |
+----+-----------+-------+---------+
|  1 | null      | val_1 | root    |
|  2 | 1         | val_2 | level_1 |
|  3 | 1         | val_3 | level_1 |
|  4 | 1         | val_4 | level_1 |
|  5 | 3         | val_5 | level_2 |
+----+-----------+-------+---------+

My problem was that when getting a collection for the first level under root level I got this message:

The discriminator column "type" is missing for "MyBundle\Entity\MyEntity" using the DQL alias "parent_a2".

This occured becasuse when Doctrine trid to fetch the parent of 1, wich is null, then the getEntity() method in ObjectHydrator.php failed.

// Parent object of relation not found, mark as not-fetched again
$element = $this->getEntity($data, $dqlAlias);

I solved the issue doing the following just above

if(!is_null($data)) continue;

Originally created by @mcanepa on GitHub (Aug 29, 2017). Originally assigned to: @Ocramius on GitHub. I have an entity "MyEntity" like ``` @ORM\InheritanceType("SINGLE_TABLE") @ORM\DiscriminatorColumn(name="type", type="string") ``` With this attribute that serves as reference to the parent ``` /** * @ORM\OneToOne(targetEntity="MyEntity") */ protected $parent; ``` In the database, data like this is stored ``` +----+-----------+-------+---------+ | id | parent_id | name | type | +----+-----------+-------+---------+ | 1 | null | val_1 | root | | 2 | 1 | val_2 | level_1 | | 3 | 1 | val_3 | level_1 | | 4 | 1 | val_4 | level_1 | | 5 | 3 | val_5 | level_2 | +----+-----------+-------+---------+ ``` My problem was that when getting a collection for the first level under root level I got this message: > The discriminator column "type" is missing for "MyBundle\\Entity\\MyEntity" using the DQL alias "parent_a2". This occured becasuse when Doctrine trid to fetch the parent of 1, wich is null, then the `getEntity()` method in `ObjectHydrator.php` failed. ``` // Parent object of relation not found, mark as not-fetched again $element = $this->getEntity($data, $dqlAlias); ``` I solved the issue doing the following just above `if(!is_null($data)) continue;`
admin added the BugInvalid labels 2026-01-22 15:14:00 +01:00
admin closed this issue 2026-01-22 15:14:00 +01:00
Author
Owner

@Ocramius commented on GitHub (Aug 29, 2017):

Can you please make a minimum reproducible test case? This is a base
scenario, so this smells a lot...

On 29 Aug 2017 17:33, "Matías Cánepa" notifications@github.com wrote:

I have an entity "MyEntity" like

@ORM\InheritanceType("SINGLE_TABLE")
@ORM\DiscriminatorColumn(name="type", type="string")

With this attribute that serves as reference to the parent

/**

  • @ORM\OneToOne(targetEntity="MyEntity")
    */
    protected $parent;

In the database, data like this is stored

+----+-----------+-------+---------+
| id | parent_id | name | type |
+----+-----------+-------+---------+
| 1 | null | val_1 | root |
| 2 | 1 | val_2 | level_1 |
| 3 | 1 | val_3 | level_1 |
| 4 | 1 | val_4 | level_1 |
| 5 | 3 | val_5 | level_2 |
+----+-----------+-------+---------+

My problem was that when getting a collection for the first level under
root level I got this message:

The discriminator column "type" is missing for "MyBundle\Entity\MyEntity"
using the DQL alias "parent_a2".

This occured becasuse when Doctrine trid to fetch the parent of 1, wich is
null, then the getEntity() method in ObjectHydrator.php failed.

// Parent object of relation not found, mark as not-fetched again
$element = $this->getEntity($data, $dqlAlias);

I solved the issue doing the following just above

if(!is_null($data)) continue;


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6656, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakBPV4h01clTOeFY38t4o9WO9557vks5sdC9BgaJpZM4PGI5T
.

@Ocramius commented on GitHub (Aug 29, 2017): Can you please make a minimum reproducible test case? This is a base scenario, so this smells a lot... On 29 Aug 2017 17:33, "Matías Cánepa" <notifications@github.com> wrote: > I have an entity "MyEntity" like > > @ORM\InheritanceType("SINGLE_TABLE") > @ORM\DiscriminatorColumn(name="type", type="string") > > With this attribute that serves as reference to the parent > > /** > * @ORM\OneToOne(targetEntity="MyEntity") > */ > protected $parent; > > In the database, data like this is stored > > +----+-----------+-------+---------+ > | id | parent_id | name | type | > +----+-----------+-------+---------+ > | 1 | null | val_1 | root | > | 2 | 1 | val_2 | level_1 | > | 3 | 1 | val_3 | level_1 | > | 4 | 1 | val_4 | level_1 | > | 5 | 3 | val_5 | level_2 | > +----+-----------+-------+---------+ > > My problem was that when getting a collection for the first level under > root level I got this message: > > The discriminator column "type" is missing for "MyBundle\Entity\MyEntity" > using the DQL alias "parent_a2". > > This occured becasuse when Doctrine trid to fetch the parent of 1, wich is > null, then the getEntity() method in ObjectHydrator.php failed. > > // Parent object of relation not found, mark as not-fetched again > $element = $this->getEntity($data, $dqlAlias); > > I solved the issue doing the following just above > > if(!is_null($data)) continue; > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6656>, or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakBPV4h01clTOeFY38t4o9WO9557vks5sdC9BgaJpZM4PGI5T> > . >
Author
Owner

@mcanepa commented on GitHub (Sep 19, 2017):

@Ocramius It took me a while to reproduce the case in a separate code. But now that I did I'm not sure if I'm doing something wrong or is actually a bug.

May be it is not doctrine at all, but how API Platorm leverage on the ORM.

I opened an issue on their side

@mcanepa commented on GitHub (Sep 19, 2017): @Ocramius It took me a while to reproduce the case in a separate code. But now that I did I'm not sure if I'm doing something wrong or is actually a bug. May be it is not doctrine at all, but how API Platorm leverage on the ORM. I opened an issue on their side
Author
Owner

@Ocramius commented on GitHub (Sep 19, 2017):

@mcanepa that's precisely the point of a test case. Can you maybe submit a PR with just the test, so it can be discussed on code, even of it ends up being invalid?

@Ocramius commented on GitHub (Sep 19, 2017): @mcanepa that's precisely the point of a test case. Can you maybe submit a PR with just the test, so it can be discussed on code, even of it ends up being invalid?
Author
Owner

@benjaminrau commented on GitHub (Sep 26, 2018):

Just to keep this up to date because i landed here searching for this issue. The bug was part of Api Platform and was solved in version 2.2: https://github.com/api-platform/core/issues/1959

@benjaminrau commented on GitHub (Sep 26, 2018): Just to keep this up to date because i landed here searching for this issue. The bug was part of Api Platform and was solved in version 2.2: https://github.com/api-platform/core/issues/1959
Author
Owner

@Ocramius commented on GitHub (Sep 26, 2018):

Closing here then.

@Ocramius commented on GitHub (Sep 26, 2018): Closing here then.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5661