#5-intelligent-groups #23
1 changed files with 8 additions and 5 deletions
|
@ -55,9 +55,10 @@ export default abstract class DynamicQueryBuilder {
|
|||
offset: number = 0,
|
||||
count: number = 25
|
||||
): SelectQueryBuilder<ObjectLiteral> {
|
||||
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(queryObj.table + "_0");
|
||||
let affix = Math.random().toString(36).substring(2);
|
||||
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(`${queryObj.table}_${affix}`);
|
||||
|
||||
this.buildDynamicQuery(query, queryObj);
|
||||
this.buildDynamicQuery(query, queryObj, affix);
|
||||
|
||||
query.offset(offset);
|
||||
query.limit(count);
|
||||
|
@ -68,9 +69,10 @@ export default abstract class DynamicQueryBuilder {
|
|||
private static buildDynamicQuery(
|
||||
query: SelectQueryBuilder<ObjectLiteral>,
|
||||
queryObject: DynamicQueryStructure,
|
||||
affix: string = "",
|
||||
depth: number = 0
|
||||
): void {
|
||||
const alias = queryObject.table + "_" + depth;
|
||||
const alias = queryObject.table + "_" + affix;
|
||||
let firstSelect = true;
|
||||
let selects: Array<string> = [];
|
||||
|
||||
|
@ -97,9 +99,10 @@ export default abstract class DynamicQueryBuilder {
|
|||
|
||||
if (queryObject.join) {
|
||||
for (const join of queryObject.join) {
|
||||
query.leftJoinAndSelect(`${alias}.${join.foreignColumn}`, join.table + "_" + (depth + 1));
|
||||
let subaffix = Math.random().toString(36).substring(2);
|
||||
query.leftJoinAndSelect(`${alias}.${join.foreignColumn}`, join.table + "_" + subaffix);
|
||||
|
||||
this.buildDynamicQuery(query, join, depth + 1);
|
||||
this.buildDynamicQuery(query, join, subaffix, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue