DDC-728: Inherited (JOINED) associations referred on DQL on owning side doesn't refer to correct table column #897

Closed
opened 2026-01-22 12:54:29 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 30, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @guilhermeblanco:

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).

Originally created by @doctrinebot on GitHub (Jul 30, 2010). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @guilhermeblanco: 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).
admin added the Bug label 2026-01-22 12:54:29 +01:00
admin closed this issue 2026-01-22 12:54:30 +01:00
Author
Owner

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

Comment created by romanb:

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

@doctrinebot commented on GitHub (Aug 7, 2010): Comment created by romanb: The first thing we need is tests to verify the issue.
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2010):

Comment created by @beberlei:

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

    /****
     * @group [DDC-728](http://www.doctrine-project.org/jira/browse/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:

dcebc241b4

@doctrinebot commented on GitHub (Aug 8, 2010): Comment created by @beberlei: I added a test to show that it works and no issue occours: ``` /**** * @group [DDC-728](http://www.doctrine-project.org/jira/browse/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
Author
Owner

@doctrinebot commented on GitHub (Aug 9, 2010):

Comment created by @guilhermeblanco:

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

Fixed. =)

@doctrinebot commented on GitHub (Aug 9, 2010): Comment created by @guilhermeblanco: I think I fixed it sometime... it was missing a condition that is now present. Fixed. =)
Author
Owner

@doctrinebot commented on GitHub (Aug 9, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 9, 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#897