DDC-8: DQL Join fails when primary key is not called "id" #5315

Closed
doctrinebot opened this Issue Sep 14, 2009 · 3 comments

1 participant

@doctrinebot

Jira issue originally created by user ablock:

A class A has a bidirectional onetomany assocation with a class B. The primary key for A is called "a_id" and is defined like this:

   /****
     * @Id @Column(name="a_id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

issuing the command ./doctrine run-dql --dql="select a from Domain3\A a join a.b b where b.id = 1" gives the following error:

PHP Notice: Undefined index: id in /home/ablock/doctrine/lib/Doctrine/ORM/Query/SqlWalker.php on line 657

Notice: Undefined index: id in /home/ablock/doctrine/lib/Doctrine/ORM/Query/SqlWalker.php on line 657
PHP Notice: Undefined index: in /home/ablock/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadata.php on line 1821

Notice: Undefined index: in /home/ablock/doctrine/lib/Doctrine/ORM/Mapping/ClassMetadata.php on line 1821
RunDql:exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE b1_.id = 1' at line 1' in /home/ablock/doctrine/lib/Doctrine/DBAL/Connection.php:602
Stack trace:
#0 /home/ablock/doctrine/lib/Doctrine/DBAL/Connection.php(602): PDO->query('SELECT a0.aid...')
#1 /home/ablock/doctrine/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): Doctrine\DBAL\Connection->execute('SELECT a0.aid...', Array)
#2 /home/ablock/doctrine/lib/Doctrine/ORM/Query.php(198): Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(Object(Doctrine\DBAL\Connection), Array)
#3 /home/ablock/doctrine/lib/Doctrine/ORM/AbstractQuery.php(461): Doctrine\ORM\Query->_doExecute(Array)
#4 /home/ablock/doctrine/lib/Doctrine/ORM/AbstractQuery.php(312): Doctrine\ORM\AbstractQuery->execute(Array, 1)
#5 /home/ablock/doctrine/lib/Doctrine/ORM/Tools/Cli/Tasks/RunDqlTask.php(105): Doctrine\ORM\AbstractQuery->getResult()
#6 /home/ablock/doctrine/lib/Doctrine/ORM/Tools/Cli.php(177): Doctrine\ORM\Tools\Cli\Tasks\RunDqlTask->run()
#7 /home/ablock/doctrine/tools/sandbox/doctrine.php(9): Doctrine\ORM\Tools\Cli->run(Array)
#8 /home/ablock/doctrine/tools/sandbox/doctrine(4): include('/home/ablock/do...')
#9 {main}

If I change the declaration to

/****
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

It works

@doctrinebot

Comment created by romanb:

This may simply be because you change the id column name but you dont change the association mapping appropriately (@JoinColumn(name..., referencedColumnName...). You probably still use "id" there.

@doctrinebot

Comment created by romanb:

You probably simply forgot to adjust the @JoinColumn to reference the new column name a_id instead of id.
If you still have issues or something is unclear, please report back.

@doctrinebot

Issue was closed with resolution "Incomplete"

@doctrinebot doctrinebot added this to the 2.0-ALPHA2 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment