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}%')`) } }