DDC-1225: Invalid SQL generated (extra comma) when joining to entity with composite PK #1540

Closed
opened 2026-01-22 13:17:22 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 23, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user darkangel:

$qb->from('Tournaments*Model*StageBracketTeamRegistration', 'r') ->innerJoin('r.teamSelection', 'ts') ->innerJoin('ts.players', 'tsp') ->select('r, ts, tsp') ->where('r.stageBracket = ?1') ->andWhere('r.opponentIsReserve = false') ->orderBy('r.registrationDateTime') ->setParameter(1, $bracket);

Generates:

SELECT s0*.id AS id0, s0_.opponent_is_reserve AS opponent_is_reserve1, s0_.opponent_checked_in AS opponent_checked_in2, s0_.registration_date_time AS registration_date_time3, t1_.id AS id4,, s0_.type AS type5, s0_.stage_bracket_id AS stage_bracket_id6, s2_.team_selection_id AS team_selection_id7, t1_.team_id AS team_id8, t3_.team_selection_id AS team_selection_id9, t3_.player_id AS player*id10 FROM stage*bracket_team_registrations s2* INNER JOIN stage*bracket_registrations s0_ ON s2_.id = s0*.id INNER JOIN team*selections t1_ ON s2_.team_selection_id = t1*.id INNER JOIN team*selection_players t3_ ON t1_.id = t3_.team_selection*id WHERE s0*.stage_bracket_id = 22 AND s0_.opponent_is*reserve = 0 ORDER BY s0*.registration_date*time ASC

Note the 2nd comma after "t1_.id AS id4". TeamSelectionPlayer uses a composite PK. I have attached the relevant entity classes.

Originally created by @doctrinebot on GitHub (Jun 23, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user darkangel: `$qb->from('Tournaments*Model*StageBracketTeamRegistration', 'r') ->innerJoin('r.teamSelection', 'ts') ->innerJoin('ts.players', 'tsp') ->select('r, ts, tsp') ->where('r.stageBracket = ?1') ->andWhere('r.opponentIsReserve = false') ->orderBy('r.registrationDateTime') ->setParameter(1, $bracket);` Generates: `SELECT s0*.id AS id0, s0_.opponent_is_reserve AS opponent_is_reserve1, s0_.opponent_checked_in AS opponent_checked_in2, s0_.registration_date_time AS registration_date_time3, t1_.id AS id4,, s0_.type AS type5, s0_.stage_bracket_id AS stage_bracket_id6, s2_.team_selection_id AS team_selection_id7, t1_.team_id AS team_id8, t3_.team_selection_id AS team_selection_id9, t3_.player_id AS player*id10 FROM stage*bracket_team_registrations s2* INNER JOIN stage*bracket_registrations s0_ ON s2_.id = s0*.id INNER JOIN team*selections t1_ ON s2_.team_selection_id = t1*.id INNER JOIN team*selection_players t3_ ON t1_.id = t3_.team_selection*id WHERE s0*.stage_bracket_id = 22 AND s0_.opponent_is*reserve = 0 ORDER BY s0*.registration_date*time ASC` Note the 2nd comma after "t1_.id AS id4". TeamSelectionPlayer uses a composite PK. I have attached the relevant entity classes.
admin added the Bug label 2026-01-22 13:17:22 +01:00
admin closed this issue 2026-01-22 13:17:24 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 28, 2011):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Jul 28, 2011): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Aug 12, 2011):

Comment created by darkangel:

Where can I find the changeset? Would it be easy for me to apply the changes to 2.1.0?

@doctrinebot commented on GitHub (Aug 12, 2011): Comment created by darkangel: Where can I find the changeset? Would it be easy for me to apply the changes to 2.1.0?
Author
Owner

@doctrinebot commented on GitHub (Aug 12, 2011):

Comment created by darkangel:

No worries, found the changes here: 196632978c

@doctrinebot commented on GitHub (Aug 12, 2011): Comment created by darkangel: No worries, found the changes here: https://github.com/doctrine/doctrine2/commit/196632978cf39bc3914e14739767cb5b72a8df9d
Author
Owner

@doctrinebot commented on GitHub (Aug 13, 2011):

Comment created by darkangel:

This is still an issue:
\

            $qb->from('Tournaments*Model*StageBracketRegisteredPlayer', 'p')
               ->select('p')
               ->where('p.stageBracket = ?1')
               ->andWhere('p.player = ?2')
               ->setParameter(1, $bracket)
               ->setParameter(2, $player)
               ->getQuery()
               ->getOneOrNullResult();

Results in:

SELECT , s0*.stage_bracket_id AS stage_bracket_id0, s0_.player_id AS player_id1, s0_.game_account_id AS game_account_id2 FROM stage_bracket_registered_players s0_ WHERE s0_.stage_bracket_id = 14 AND s0_.player*id = 5
@doctrinebot commented on GitHub (Aug 13, 2011): Comment created by darkangel: This is still an issue: \ ``` $qb->from('Tournaments*Model*StageBracketRegisteredPlayer', 'p') ->select('p') ->where('p.stageBracket = ?1') ->andWhere('p.player = ?2') ->setParameter(1, $bracket) ->setParameter(2, $player) ->getQuery() ->getOneOrNullResult(); ``` Results in: ``` SELECT , s0*.stage_bracket_id AS stage_bracket_id0, s0_.player_id AS player_id1, s0_.game_account_id AS game_account_id2 FROM stage_bracket_registered_players s0_ WHERE s0_.stage_bracket_id = 14 AND s0_.player*id = 5 ```
Author
Owner

@doctrinebot commented on GitHub (Aug 14, 2011):

Comment created by @guilhermeblanco:

Hi,

I attempted to create a failing test case for this issue, but either the provided entities are not enough or the issue is not reproducible anymore (it was already fixed in latest 2.2-DEV).

Could you please try to compile everything into a test case?

Cheers,

@doctrinebot commented on GitHub (Aug 14, 2011): Comment created by @guilhermeblanco: Hi, I attempted to create a failing test case for this issue, but either the provided entities are not enough or the issue is not reproducible anymore (it was already fixed in latest 2.2-DEV). Could you please try to compile everything into a test case? Cheers,
Author
Owner

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

Comment created by darkangel:

Hi Guilherme,

I'll attach 2 simple entities for testing. You can run the following query:
\

        $qb->from('App*Model*TestEntity1', 'te1')
           ->select('te1')
           ->where('te1.testEntity2 = ?1')
           ->setParameter(1, 0)
           ->getQuery()
           ->getOneOrNullResult();

I'm running this against 2.1.0 + this change.

Thanks.

@doctrinebot commented on GitHub (Aug 15, 2011): Comment created by darkangel: Hi Guilherme, I'll attach 2 simple entities for testing. You can run the following query: \ ``` $qb->from('App*Model*TestEntity1', 'te1') ->select('te1') ->where('te1.testEntity2 = ?1') ->setParameter(1, 0) ->getQuery() ->getOneOrNullResult(); ``` I'm running this against 2.1.0 + [this](https://github.com/doctrine/doctrine2/commit/196632978cf39bc3914e14739767cb5b72a8df9d) change. Thanks.
Author
Owner

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

Comment created by @guilhermeblanco:

Fixed in this commit 6857134f36

Thanks for the report!

@doctrinebot commented on GitHub (Aug 15, 2011): Comment created by @guilhermeblanco: Fixed in this commit https://github.com/doctrine/doctrine2/commit/6857134f36097187ab2f0d932f4f1d9ffab12854 Thanks for the report!
Author
Owner

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

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 15, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Aug 29, 2011):

Comment created by @beberlei:

Merged into 2.1.x

@doctrinebot commented on GitHub (Aug 29, 2011): Comment created by @beberlei: Merged into 2.1.x
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1540