From f85bd02b113c931b5de48e18b69e99b40caf8838 Mon Sep 17 00:00:00 2001 From: Jakob Wagner Date: Sat, 14 Jan 2023 18:40:00 +0100 Subject: [PATCH] fix: fixed a problem for uppercase fields on search by (#446) --- src/paginate.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/paginate.ts b/src/paginate.ts index 22a9e49..60fad22 100644 --- a/src/paginate.ts +++ b/src/paginate.ts @@ -302,11 +302,18 @@ export async function paginate( propertyPath.length > 1 && queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(propertyPath[0]) - const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}` - if (['postgres', 'cockroachdb'].includes(queryBuilder.connection.options.type)) { + const alias = hasRelation ? `"${qb.alias}"_` : `"${qb.alias}".` + let columns = '' + + for (const property of propertyPath) { + columns += `"${property}".` + } + const aliasColumn = alias + columns.substring(0, columns.length - 1) + qb.orWhere(`${aliasColumn}::text ILIKE '%${query.search}%'`) } else { + const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}` qb.orWhere(`UPPER(${aliasColumn}) LIKE UPPER('%${query.search}%')`) } }