DDC-739: DQL generates wrong SQL if id column has other name #911

Closed
opened 2026-01-22 12:55:15 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 9, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user musuk:

I created many to many relation User <-> Group same as CmsUser and CmsGroup in test.
But by User class has another definition for ID column:

class User
{
    /****
     * @Id @Column(name="Id", type="integer")
     * @GeneratedValue
     */
    private $id;
   ...

My DQL is:

$queryBuilder->select("g")->from("Group", "g")->join("g.users", "u");

It generates wrong sql:

SELECT g0*.Id AS Id0, g0_.name AS name1 FROM groups g0_ INNER JOIN users_groups u2_ ON g0_. = u2_.group_id INNER JOIN users u1_ ON u1_. = u2_.user*id

As you see g0_. has ho id column.
If I removes name="Id" from id column definition

class User
{
    /****
     * @Id @Column(type="integer")
     * @GeneratedValue
     */
    private $id;
   ...

all works fine and generated sql is:

SELECT g0*.id AS id0, g0_.name AS name1 FROM groups g0_ INNER JOIN users_groups u2_ ON g0_.id = u2_.group_id INNER JOIN users u1_ ON u1_.id = u2_.user*id
Originally created by @doctrinebot on GitHub (Aug 9, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user musuk: I created many to many relation User <-> Group same as CmsUser and CmsGroup in test. But by User class has another definition for ID column: ``` java class User { /**** * @Id @Column(name="Id", type="integer") * @GeneratedValue */ private $id; ... ``` My DQL is: ``` java $queryBuilder->select("g")->from("Group", "g")->join("g.users", "u"); ``` It generates wrong sql: ``` sql SELECT g0*.Id AS Id0, g0_.name AS name1 FROM groups g0_ INNER JOIN users_groups u2_ ON g0_. = u2_.group_id INNER JOIN users u1_ ON u1_. = u2_.user*id ``` As you see g0_. has ho id column. If I removes **name="Id"** from id column definition ``` java class User { /**** * @Id @Column(type="integer") * @GeneratedValue */ private $id; ... ``` all works fine and generated sql is: ``` sql SELECT g0*.id AS id0, g0_.name AS name1 FROM groups g0_ INNER JOIN users_groups u2_ ON g0_.id = u2_.group_id INNER JOIN users u1_ ON u1_.id = u2_.user*id ```
admin added the Bug label 2026-01-22 12:55:15 +01:00
admin closed this issue 2026-01-22 12:55:16 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2010):

Comment created by @guilhermeblanco:

Assigning to me

@doctrinebot commented on GitHub (Aug 11, 2010): Comment created by @guilhermeblanco: Assigning to me
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2010):

Comment created by @guilhermeblanco:

Please public your Group and User mappings... I have tested here and could not reproduce the issue.

Cheers,

@doctrinebot commented on GitHub (Aug 11, 2010): Comment created by @guilhermeblanco: Please public your Group and User mappings... I have tested here and could not reproduce the issue. Cheers,
Author
Owner

@doctrinebot commented on GitHub (Aug 15, 2010):

Comment created by @beberlei:

This is probably a bug on the other side missing a correct @joinColumn annotation?

@doctrinebot commented on GitHub (Aug 15, 2010): Comment created by @beberlei: This is probably a bug on the other side missing a correct @joinColumn annotation?
Author
Owner

@doctrinebot commented on GitHub (Aug 30, 2010):

Comment created by romanb:

We need a complete (failing) unit test in order to proceed on this. Scheduling for RC1.

@doctrinebot commented on GitHub (Aug 30, 2010): Comment created by romanb: We need a complete (failing) unit test in order to proceed on this. Scheduling for RC1.
Author
Owner

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

Comment created by @beberlei:

This is for sure an error in the @joinColumn specification (or no @joinColumn at all) i close this issue until further feedback is given.

@doctrinebot commented on GitHub (Sep 15, 2010): Comment created by @beberlei: This is for sure an error in the @joinColumn specification (or no @joinColumn at all) i close this issue until further feedback is given.
Author
Owner

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

Issue was closed with resolution "Cannot Reproduce"

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

No dependencies set.

Reference: doctrine/archived-orm#911