Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 4 comments

2 participants

@doctrinebot

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

@doctrinebot

Comment created by romanb:

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

@doctrinebot

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

@doctrinebot

Comment created by @guilhermeblanco:

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

Fixed. =)

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-BETA4 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.