Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

doctrinebot opened this issue Sep 14, 2009 · 3 comments
Labels
Milestone

Comments

@doctrinebot
Copy link

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

@doctrinebot
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Issue was closed with resolution "Incomplete"

@doctrinebot doctrinebot added this to the 2.0-ALPHA2 milestone 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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant