DDC-497: find() and findAll() on Repository do not work when SINGLE_TABLE inheritance is used #620

Closed
opened 2026-01-22 12:44:51 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 5, 2010).

Jira issue originally created by user ditte:

Class Orm\Models\Car:

    @Entity
    @Table(name="cars")
    @InheritanceType("SINGLE_TABLE")
    @DiscriminatorColumn(name="discr", type="string")
    @DiscriminatorMap({"car" = "Orm\Models\Car", "bluecar" = "Orm\Models\BlueCar"})

Class Orm\Models\BlueCar extends Orm\Models\Car:

    @Entity

Now my Database holds 4 records:

    id  title       discr
    1   blue car    bluecar
    2   only Car    car
    5   blue car2   bluecar
    6   only Car2 car

Now querying objects by Repository leads to some errors.


    //quering for all BlueCars
    $em->getRepository('Orm\Models\BlueCar')->findAll();

    //the result set counts 4 objects
    blue car    : Orm\Models\BlueCar
            : Orm\Models\Car
    blue car2   : Orm\Models\BlueCar
            : Orm\Models\Car

    //The 2 Car Items where the title is missing are to much for this result set, and useless
    // there is also a php notice coming up for each Orm\Models\Car object
    Notice: Undefined index: id in /library/Doctrine/ORM/UnitOfWork.php  on line 1727
    I use mysql as Database and so the sql query looks like this.

    "SELECT c0.id AS id1, c0.title AS title2, discr FROM cars c0"

    It seems that the query is missing the where discriminator = "bluecar" part

querying for Car
    $em->getRepository('Orm\Models\Car')->findAll();

    blue car: Orm\Models\BlueCar
    only Car: Orm\Models\Car
    blue car2: Orm\Models\BlueCar
    only Car2: Orm\Models\Car

    Is working without errors but i think it is a mere chance if you look at the query
    "SELECT c0.id AS id1, c0.title AS title2, discr FROM cars c0" it is the same.

    I am not shure if it is intended that quering for Cars also returns BlueCars but due to the behavior when using DQL for quering, i guess it is right.
    That means, when using DQL:

    $q = $em->createQuery('select u from Orm\Models\BlueCar u');
    $results = $q->execute();

    everything works as expected, so using a custom EntityRepository and override find, findAll and so on is a workaround. So this is a minor bug ?
Originally created by @doctrinebot on GitHub (Apr 5, 2010). Jira issue originally created by user ditte: ``` Class Orm\Models\Car: @Entity @Table(name="cars") @InheritanceType("SINGLE_TABLE") @DiscriminatorColumn(name="discr", type="string") @DiscriminatorMap({"car" = "Orm\Models\Car", "bluecar" = "Orm\Models\BlueCar"}) Class Orm\Models\BlueCar extends Orm\Models\Car: @Entity Now my Database holds 4 records: id title discr 1 blue car bluecar 2 only Car car 5 blue car2 bluecar 6 only Car2 car Now querying objects by Repository leads to some errors. //quering for all BlueCars $em->getRepository('Orm\Models\BlueCar')->findAll(); //the result set counts 4 objects blue car : Orm\Models\BlueCar : Orm\Models\Car blue car2 : Orm\Models\BlueCar : Orm\Models\Car //The 2 Car Items where the title is missing are to much for this result set, and useless // there is also a php notice coming up for each Orm\Models\Car object Notice: Undefined index: id in /library/Doctrine/ORM/UnitOfWork.php on line 1727 I use mysql as Database and so the sql query looks like this. "SELECT c0.id AS id1, c0.title AS title2, discr FROM cars c0" It seems that the query is missing the where discriminator = "bluecar" part querying for Car $em->getRepository('Orm\Models\Car')->findAll(); blue car: Orm\Models\BlueCar only Car: Orm\Models\Car blue car2: Orm\Models\BlueCar only Car2: Orm\Models\Car Is working without errors but i think it is a mere chance if you look at the query "SELECT c0.id AS id1, c0.title AS title2, discr FROM cars c0" it is the same. I am not shure if it is intended that quering for Cars also returns BlueCars but due to the behavior when using DQL for quering, i guess it is right. That means, when using DQL: $q = $em->createQuery('select u from Orm\Models\BlueCar u'); $results = $q->execute(); everything works as expected, so using a custom EntityRepository and override find, findAll and so on is a workaround. So this is a minor bug ? ```
admin added the Bug label 2026-01-22 12:44:51 +01:00
admin closed this issue 2026-01-22 12:44:52 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 5, 2010):

@doctrinebot commented on GitHub (Apr 5, 2010): - relates to [DDC-500: Single Table Inheritance Selects](http://www.doctrine-project.org/jira/browse/DDC-500)
Author
Owner

@doctrinebot commented on GitHub (Apr 5, 2010):

Comment created by romanb:

You mention ALPHA4 as the affected version. Did you test this with trunk?

@doctrinebot commented on GitHub (Apr 5, 2010): Comment created by romanb: You mention ALPHA4 as the affected version. Did you test this with trunk?
Author
Owner

@doctrinebot commented on GitHub (Apr 5, 2010):

Comment created by romanb:

@"I am not shure if it is intended that quering for Cars also returns BlueCars but due to the behavior when using DQL for quering, i guess it is right."

Of course. Anything else would be wrong. If you query for cars you get all cars. BlueCars are Cars.

@doctrinebot commented on GitHub (Apr 5, 2010): Comment created by romanb: @"I am not shure if it is intended that quering for Cars also returns BlueCars but due to the behavior when using DQL for quering, i guess it is right." Of course. Anything else would be wrong. If you query for cars you get all cars. BlueCars are Cars.
Author
Owner

@doctrinebot commented on GitHub (Apr 7, 2010):

Comment created by ditte:

Tested with Revision: 7533.

@doctrinebot commented on GitHub (Apr 7, 2010): Comment created by ditte: Tested with Revision: 7533.
Author
Owner

@doctrinebot commented on GitHub (Apr 26, 2010):

Comment created by romanb:

Fixed in 760ea34a0c

@doctrinebot commented on GitHub (Apr 26, 2010): Comment created by romanb: Fixed in http://github.com/doctrine/doctrine2/commit/760ea34a0cc3cae4e3caea17e8aab6ceb74ecace
Author
Owner

@doctrinebot commented on GitHub (Apr 26, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Apr 26, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#620