Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-728

Inherited (JOINED) associations referred on DQL on owning side doesn't refer to correct table column

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-BETA4
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Based on code instrospection, it seems that SQL generated is wrong when you attempt to do something like this:

      SELECT m FROM CompanyManager m WHERE m.InheritedSingleValuedAssociation = ?1
      

      It seems the column that refers to the association points to wrong table (apparently it points to CompanyManager table).
      If everything works, we still need to have coverage to it (we have none).

        Activity

        Hide
        Roman S. Borschel added a comment -

        The first thing we need is tests to verify the issue.

        Show
        Roman S. Borschel added a comment - The first thing we need is tests to verify the issue.
        Hide
        Benjamin Eberlei added a comment -

        I added a test to show that it works and no issue occours:

            /**
             * @group DDC-728
             */
            public function testQueryForInheritedSingleValuedAssociation()
            {
                $manager = new CompanyManager();
                $manager->setName('gblanco');
                $manager->setSalary(1234);
                $manager->setTitle('Awesome!');
                $manager->setDepartment('IT');
        
                $person = new CompanyPerson();
                $person->setName('spouse');
        
                $manager->setSpouse($person);
        
                $this->_em->persist($manager);
                $this->_em->persist($person);
                $this->_em->flush();
                $this->_em->clear();
        
                $dql = "SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m WHERE m.spouse = ?1";
                $dqlManager = $this->_em->createQuery($dql)->setParameter(1, $person->getId())->getSingleResult();
        
                $this->assertEquals($manager->getId(), $dqlManager->getId());
                $this->assertEquals($person->getId(), $dqlManager->getSpouse()->getId());
            }
        

        Its in Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php, see commit:

        http://github.com/doctrine/doctrine2/commit/dcebc241b4e36f20f364699105aff258f5840962

        Show
        Benjamin Eberlei added a comment - I added a test to show that it works and no issue occours: /** * @group DDC-728 */ public function testQueryForInheritedSingleValuedAssociation() { $manager = new CompanyManager(); $manager->setName('gblanco'); $manager->setSalary(1234); $manager->setTitle('Awesome!'); $manager->setDepartment('IT'); $person = new CompanyPerson(); $person->setName('spouse'); $manager->setSpouse($person); $ this ->_em->persist($manager); $ this ->_em->persist($person); $ this ->_em->flush(); $ this ->_em->clear(); $dql = "SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m WHERE m.spouse = ?1" ; $dqlManager = $ this ->_em->createQuery($dql)->setParameter(1, $person->getId())->getSingleResult(); $ this ->assertEquals($manager->getId(), $dqlManager->getId()); $ this ->assertEquals($person->getId(), $dqlManager->getSpouse()->getId()); } Its in Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php, see commit: http://github.com/doctrine/doctrine2/commit/dcebc241b4e36f20f364699105aff258f5840962
        Hide
        Guilherme Blanco added a comment -

        I think I fixed it sometime... it was missing a condition that is now present.

        Fixed. =)

        Show
        Guilherme Blanco added a comment - I think I fixed it sometime... it was missing a condition that is now present. Fixed. =)

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Guilherme Blanco
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: