mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
escape alias & columns in findRoots
This commit is contained in:
parent
2919b8530d
commit
c6e8dd285c
@ -33,9 +33,13 @@ export class TreeRepository<Entity> extends Repository<Entity> {
|
||||
*/
|
||||
findRoots(): Promise<Entity[]> {
|
||||
|
||||
const parentPropertyName = this.metadata.treeParentRelation!.propertyName;
|
||||
const parentPropertyName = this.metadata.treeParentRelation!.propertyName + "Id";
|
||||
const escapeAlias = (alias: string) => this.manager.connection.driver.escapeAlias(alias);
|
||||
const escapeColumn = (column: string) => this.manager.connection.driver.escapeColumn(column);
|
||||
|
||||
return this.createQueryBuilder("treeEntity")
|
||||
.where(`treeEntity.${parentPropertyName}Id IS NULL`)
|
||||
.from(this.metadata.target, "treeEntity")
|
||||
.where(`${escapeAlias("treeEntity")}.${escapeColumn(parentPropertyName)} IS NULL`)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
@ -52,6 +56,7 @@ export class TreeRepository<Entity> extends Repository<Entity> {
|
||||
return this.createQueryBuilder(alias)
|
||||
.innerJoin(this.metadata.closureJunctionTable.tableName, closureTableAlias, joinCondition)
|
||||
.where(`${escapeAlias(closureTableAlias)}.${escapeColumn("ancestor")}=${this.metadata.getEntityIdMap(entity)![this.metadata.primaryColumns[0].propertyName]}`);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user