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 19, 2020
1 parent f336657 commit 5687f88
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 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,13 @@ 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}`;
else return `"${this.alias}"."${field}"`;
case 2:
return field;
default:
Expand All @@ -797,7 +798,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 5687f88

Please sign in to comment.