Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relationLoadStrategy query: ER_NONUNIQ_TABLE during recursive call #9936

Open
1 of 18 tasks
Greg57070 opened this issue Apr 11, 2023 · 1 comment · May be fixed by #10824
Open
1 of 18 tasks

relationLoadStrategy query: ER_NONUNIQ_TABLE during recursive call #9936

Greg57070 opened this issue Apr 11, 2023 · 1 comment · May be fixed by #10824

Comments

@Greg57070
Copy link

Issue description

relationLoadStrategy query: ER_NONUNIQ_TABLE during recursive call

Expected Behavior

When using a ManyToOne from an Entity to the same Entity, TypeORM should use an alias when joining the table

Actual Behavior

The table "Folder" is called twice with the same alias :

SELECT Folder.id AS Folder_id,
Folder.familyLinkId AS Folder_familyLinkId,
Folder.id AS Folder_id,
Folder.familyLinkId AS Folder_familyLinkId
FROM folder Folder
INNER JOIN folder Folder ON Folder.familyLinkId = Folder.id
WHERE Folder.id IN (7486)

Steps to reproduce

@entity()
export class Folder {

@PrimaryGeneratedColumn()
id: number;

@OneToMany((type) => Folder, (folder) => folder.family_link)
@JoinTable()
linked_folders: Folder[];

@ManyToOne((type) => Folder, (folder) => folder.linked_folders, {
	nullable: true,
})
family_link: Folder;

}

folders = await folderRepository.find({
relationLoadStrategy: "query",
where: { id: In(foldersID) },
relations: {
family_link: true
}
})

My Environment

Dependency Version
Operating System
Node.js version 18.15.0
Typescript version 4.9.5
TypeORM version 0.3.12

Additional Context

IMHO (I'm really not a javascript dev 😅), I think the problem is in FindOptionsUtils.ts, in applyRelationsRecursively.
In case of relationLoadStrategy query, it use "relation" but not "relationAlias"

Thank you all for the good work, keep up with it !

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

@monrostar
Copy link

I would like to get this fix into the new version of Typeorm as soon as possible because we have a table with these relationships that cause a problem when using relationLoadStrategy: 'query'

My current error that we need to bypass in every query manually right now
During the creation of join typeorm creates relations with the same alias as the table we are trying to get data from

Error: table name "Collection" specified more than once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants