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

Closed
opened 2026-01-22 12:24:04 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 14, 2009).

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_.a_id...')
#1 /home/ablock/doctrine/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): Doctrine\DBAL\Connection->execute('SELECT a0_.a_id...', 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

Originally created by @doctrinebot on GitHub (Sep 14, 2009). 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_.a_id...') #1 /home/ablock/doctrine/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php(42): Doctrine\DBAL\Connection->execute('SELECT a0_.a_id...', 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
admin added the Bug label 2026-01-22 12:24:04 +01:00
admin closed this issue 2026-01-22 12:24:05 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2009):

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 commented on GitHub (Sep 15, 2009): 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.
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2009):

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 commented on GitHub (Sep 15, 2009): 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.
Author
Owner

@doctrinebot commented on GitHub (Sep 15, 2009):

Issue was closed with resolution "Incomplete"

@doctrinebot commented on GitHub (Sep 15, 2009): Issue was closed with resolution "Incomplete"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11