DDC-163: Not unique alias error when using the same manyToMany relation from two entity with different alias #201

Closed
opened 2026-01-22 12:30:22 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 20, 2009).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user rickdt:

I think the sample sql speak for himself ...

Error :

SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'f4_'

DQL :

SELECT client 
FROM Entity\Client client 
LEFT JOIN client.client*fna client*fna 
LEFT JOIN client.spouse*fna spouse*fna LEFT 
JOIN client*fna.users client*user 
LEFT JOIN spouse*fna.users spouse*user 
WHERE (client.id = :client*id) AND ((client_user.id = :user) OR (spouse*user.id = :user))

SQL (mysql):

SELECT f0*.display_name AS display_name0 FROM fna_client f0* 
LEFT JOIN fna*fna f1_ ON f0_.fna_client_fna_id = f1*.id 
LEFT JOIN fna*fna f2_ ON f0_.fna_spouse_fna_id = f2*.id 
LEFT JOIN fna*fna_user f4_ ON f1_.id = f4_.fna*id 
LEFT JOIN fna*user f3_ ON f3_.id = f4_.user*id 
LEFT JOIN fna*fna_user f4_ ON f2_.id = f4_.fna*id 
LEFT JOIN fna*user f5_ ON f5_.id = f4_.user*id 
WHERE (f0*.id = ?) AND ((f3_.id = ?) OR (f5*.id = ?))
Originally created by @doctrinebot on GitHub (Nov 20, 2009). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user rickdt: I think the sample sql speak for himself ... Error : ``` SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'f4_' ``` DQL : ``` SELECT client FROM Entity\Client client LEFT JOIN client.client*fna client*fna LEFT JOIN client.spouse*fna spouse*fna LEFT JOIN client*fna.users client*user LEFT JOIN spouse*fna.users spouse*user WHERE (client.id = :client*id) AND ((client_user.id = :user) OR (spouse*user.id = :user)) ``` SQL (mysql): ``` SELECT f0*.display_name AS display_name0 FROM fna_client f0* LEFT JOIN fna*fna f1_ ON f0_.fna_client_fna_id = f1*.id LEFT JOIN fna*fna f2_ ON f0_.fna_spouse_fna_id = f2*.id LEFT JOIN fna*fna_user f4_ ON f1_.id = f4_.fna*id LEFT JOIN fna*user f3_ ON f3_.id = f4_.user*id LEFT JOIN fna*fna_user f4_ ON f2_.id = f4_.fna*id LEFT JOIN fna*user f5_ ON f5_.id = f4_.user*id WHERE (f0*.id = ?) AND ((f3_.id = ?) OR (f5*.id = ?)) ```
admin added the Bug label 2026-01-22 12:30:22 +01:00
admin closed this issue 2026-01-22 12:30:22 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 20, 2009):

Comment created by rickdt:

In the previous example, please note the "fna_fna_user" intersection table who have the same alias.

@doctrinebot commented on GitHub (Nov 20, 2009): Comment created by rickdt: In the previous example, please note the "fna_fna_user" intersection table who have the same alias.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by @beberlei:

Hello Eric,

its very hard to get from here to a test-case that can reproduce the issue, also given that the naming is very confusing for somebody not into the specifics of your domain.

Can you try to set-up a simple phpunit test a reproduce case? You can take a hint at trunk/libs/Doctrine/Tests/ORM/Functional/Ticket/DDC*.php how they can be organized easily.

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by @beberlei: Hello Eric, its very hard to get from here to a test-case that can reproduce the issue, also given that the naming is very confusing for somebody not into the specifics of your domain. Can you try to set-up a simple phpunit test a reproduce case? You can take a hint at trunk/libs/Doctrine/Tests/ORM/Functional/Ticket/DDC*.php how they can be organized easily.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

I would be happy to create you a test case.

I may not have what is needed in current Tests Models available. Do you know a Model entity which correspond to the following pattern :

I need 2 entity (Entity1 and Entity2)

Between both entity, there is two OneToOne relation with different meaning.

Entity1.entity2_relation1 -> entity2
Entity1.entity2_relation2 -> entity2

Ex: Company and Contact
Company.employee -> Contact
Company.manager -> Contact

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: I would be happy to create you a test case. I may not have what is needed in current Tests Models available. Do you know a Model entity which correspond to the following pattern : I need 2 entity (Entity1 and Entity2) Between both entity, there is two OneToOne relation with different meaning. Entity1.entity2_relation1 -> entity2 Entity1.entity2_relation2 -> entity2 Ex: Company and Contact Company.employee -> Contact Company.manager -> Contact
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

I will try o use the CompanyPerson entity

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: I will try o use the CompanyPerson entity
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by rickdt:

Here is the test case.

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by rickdt: Here is the test case.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2010):

Comment created by @beberlei:

Thank you very much. I will look into it tonight.

For The Ticket test-cases we normally create entities lying in the same Ticket Test file and name them Ticket163* to generate a specific re-produce case. However its much better with one of the existing models of course, because its easier to grasp :-)

@doctrinebot commented on GitHub (Feb 3, 2010): Comment created by @beberlei: Thank you very much. I will look into it tonight. For The Ticket test-cases we normally create entities lying in the same Ticket Test file and name them Ticket163\* to generate a specific re-produce case. However its much better with one of the existing models of course, because its easier to grasp :-)
Author
Owner

@doctrinebot commented on GitHub (Feb 7, 2010):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Feb 7, 2010): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Feb 7, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 7, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/24eafcfa1f84be9e6374

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/24eafcfa1f84be9e6374 - [10340_DDC163Test.php](https://gist.github.com/24eafcfa1f84be9e6374#file-10340_DDC163Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#201