Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-497

find() and findAll() on Repository do not work when SINGLE_TABLE inheritance is used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MacOsX 10.6.2 - Zend Server 4.0.6 - PHP 5.3 - MySql 5.1.40

      Description

       
      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 ?
      

        Issue Links

          Activity

          Marcus created issue -
          Marcus made changes -
          Field Original Value New Value
          Description 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, fixes the issue. So this is a minor bug ?




          {noformat}
          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, fixes the issue. So this is a minor bug ?
          {noformat}



          Marcus made changes -
          Description {noformat}
          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, fixes the issue. So this is a minor bug ?
          {noformat}



          {noformat}
          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 ?
          {noformat}



          Hide
          Roman S. Borschel added a comment -

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

          Show
          Roman S. Borschel added a comment - You mention ALPHA4 as the affected version. Did you test this with trunk?
          Hide
          Roman S. Borschel added a comment -

          @"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.

          Show
          Roman S. Borschel added a comment - @"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.
          Hide
          Marcus added a comment -

          Tested with Revision: 7533.

          Show
          Marcus added a comment - Tested with Revision: 7533.
          Roman S. Borschel made changes -
          Link This issue relates to DDC-500 [ DDC-500 ]
          Roman S. Borschel made changes -
          Fix Version/s 2.0-BETA1 [ 10030 ]
          Roman S. Borschel made changes -
          Priority Minor [ 4 ] Critical [ 2 ]
          Show
          Roman S. Borschel added a comment - Fixed in http://github.com/doctrine/doctrine2/commit/760ea34a0cc3cae4e3caea17e8aab6ceb74ecace
          Roman S. Borschel made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Benjamin Eberlei made changes -
          Workflow jira [ 11174 ] jira-feedback [ 15609 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 15609 ] jira-feedback2 [ 17473 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 17473 ] jira-feedback3 [ 19730 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-497, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              Roman S. Borschel
              Reporter:
              Marcus
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: