QueryBulder -> join alias parameter not expect 'as' word as alias #6826

Open
opened 2026-01-22 15:39:35 +01:00 by admin · 1 comment
Owner

Originally created by @Zlyy on GitHub (Sep 14, 2021).

Bug Report

| Version | 2.9.3

Summary

When I tried to use 'as' word as alias (not without reason - entity name was AddonSupplier and according to my company code standards we use first letters of entity name) - I got unclear exception message. Of course I know that using words like this as alias is very bad practice, but I did this without thinking.

Current behavior

$builder ->select('ad') ->from(AddonDesign::class, 'ad')->join('ad.parent', 'as')->join('as.parent', 'a')->where('a = :addon')->setParameter('addon', $this->addon);

DQL from exception:
SELECT COUNT(ad.id) FROM App\Addons\Entity\AddonDesign ad INNER JOIN ad.parent as INNER JOIN as.parent a WHERE a = :addon

Misleading exception message:
And exception message, which is in my mind misleading:
[Semantical Error] line 0, col 95 near '.parent a WHERE': Error: Identification Variable as used in join path expression but was not defined before.

Expected behavior

Aliases should be check or error message should be fixed

Exception with message that I cant use 'as' word as an alias.

Originally created by @Zlyy on GitHub (Sep 14, 2021). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Version | 2.9.3 #### Summary When I tried to use 'as' word as alias (not without reason - entity name was AddonSupplier and according to my company code standards we use first letters of entity name) - I got unclear exception message. Of course I know that using words like this as alias is very bad practice, but I did this without thinking. <!-- Provide a summary describing the problem you are experiencing. --> #### Current behavior ` $builder ->select('ad') ->from(AddonDesign::class, 'ad')->join('ad.parent', 'as')->join('as.parent', 'a')->where('a = :addon')->setParameter('addon', $this->addon);` DQL from exception: `SELECT COUNT(ad.id) FROM App\Addons\Entity\AddonDesign ad INNER JOIN ad.parent as INNER JOIN as.parent a WHERE a = :addon` <!-- What is the current (buggy) behavior? --> Misleading exception message: And exception message, which is in my mind misleading: `[Semantical Error] line 0, col 95 near '.parent a WHERE': Error: Identification Variable as used in join path expression but was not defined before.` #### Expected behavior Aliases should be check or error message should be fixed <!-- What was the expected (correct) behavior? --> Exception with message that I cant use 'as' word as an alias.
Author
Owner

@greg0ire commented on GitHub (Sep 15, 2021):

Possible next step: write a test to reproduce this. tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php could be used as a template since it involves ->join too.

@greg0ire commented on GitHub (Sep 15, 2021): Possible next step: write a test to reproduce this. `tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1757Test.php` could be used as a template since it involves `->join` too.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6826