fix: fixed a problem for uppercase fields on search by (#446)

This commit is contained in:
Jakob Wagner 2023-01-14 18:40:00 +01:00 committed by GitHub
parent 4f3898b273
commit f85bd02b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,11 +302,18 @@ export async function paginate<T extends ObjectLiteral>(
propertyPath.length > 1 && propertyPath.length > 1 &&
queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(propertyPath[0]) queryBuilder.expressionMap.mainAlias.metadata.hasRelationWithPropertyPath(propertyPath[0])
const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}`
if (['postgres', 'cockroachdb'].includes(queryBuilder.connection.options.type)) { 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}%'`) qb.orWhere(`${aliasColumn}::text ILIKE '%${query.search}%'`)
} else { } else {
const aliasColumn = hasRelation ? `${qb.alias}_${column}` : `${qb.alias}.${column}`
qb.orWhere(`UPPER(${aliasColumn}) LIKE UPPER('%${query.search}%')`) qb.orWhere(`UPPER(${aliasColumn}) LIKE UPPER('%${query.search}%')`)
} }
} }