Skip to content

Commit

Permalink
fix(typeorm): query wrong generated
Browse files Browse the repository at this point in the history
  • Loading branch information
joennlae committed Apr 20, 2020
1 parent f336657 commit 353e902
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/crud-typeorm/src/typeorm-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,15 @@ export class TypeOrmCrudService<T> extends CrudService<T> {
: {};
}

protected getFieldWithAlias(field: string) {
protected getFieldWithAlias(field: string, sort: boolean = false) {
const cols = field.split('.');
// relation is alias
switch (cols.length) {
case 1:
return `${this.alias}.${field}`;
if (sort || this.alias[0] === '"') {
return `${this.alias}.${field}`;
}
return `"${this.alias}"."${field}"`;
case 2:
return field;
default:
Expand All @@ -797,7 +800,7 @@ export class TypeOrmCrudService<T> extends CrudService<T> {
const params: ObjectLiteral = {};

for (let i = 0; i < sort.length; i++) {
const field = this.getFieldWithAlias(sort[i].field);
const field = this.getFieldWithAlias(sort[i].field, true);
const checkedFiled = this.checkSqlInjection(field);
params[checkedFiled] = sort[i].order;
}
Expand Down

0 comments on commit 353e902

Please sign in to comment.