Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-8

DQL Join fails when primary key is not called "id"

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Incomplete
    • Affects Version/s: 2.0-ALPHA2
    • Fix Version/s: 2.0-ALPHA2
    • Component/s: DQL, ORM
    • Security Level: All
    • Labels:
      None

      Description

      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

        Activity

        Hide
        Roman S. Borschel added a comment -

        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.

        Show
        Roman S. Borschel added a comment - 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.
        Hide
        Roman S. Borschel added a comment -

        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.

        Show
        Roman S. Borschel added a comment - 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.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Avi Block
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: