From 130b8a4bf8a4c481a647dad6dbaef1434426e1a0 Mon Sep 17 00:00:00 2001 From: Matthias Zettler Date: Thu, 13 Oct 2022 21:15:04 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20prevent=20duplicate=20col?= =?UTF-8?q?umn=20names=20when=20using=20limit=20param?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using limit parameter on getMany() and eager loading of nested entities the query failed because of duplicate column names. Primary columns where selected twice. --- packages/crud-typeorm/src/typeorm-crud.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/crud-typeorm/src/typeorm-crud.service.ts b/packages/crud-typeorm/src/typeorm-crud.service.ts index e6118a30..a235f29b 100644 --- a/packages/crud-typeorm/src/typeorm-crud.service.ts +++ b/packages/crud-typeorm/src/typeorm-crud.service.ts @@ -568,7 +568,7 @@ export class TypeOrmCrudService extends CrudService { ...allowedRelation.primaryColumns, ...(isArrayFull(options.persist) ? options.persist : []), ...columns, - ].map((col) => `${alias}.${col}`); + ].filter((n, i, self) => self.indexOf(n) === i).map((col) => `${alias}.${col}`); builder.addSelect(select); } @@ -787,7 +787,7 @@ export class TypeOrmCrudService extends CrudService { ...(options.persist && options.persist.length ? options.persist : []), ...columns, ...this.entityPrimaryColumns, - ].map((col) => `${this.alias}.${col}`); + ].filter((n, i, self) => self.indexOf(n) === i).map((col) => `${this.alias}.${col}`); return select; }