Fix some MSSQL test cases.

This commit is contained in:
Sam Rose 2024-09-04 16:41:36 +01:00
parent e90aff959f
commit cda778598d
No known key found for this signature in database
1 changed files with 8 additions and 6 deletions

View File

@ -973,16 +973,18 @@ class InternalBuilder {
subQuery = this.addJoinFieldCheck(subQuery, relationship)
}
let wrapperQuery: Knex.QueryBuilder | Knex.Raw
if (this.client === SqlClient.MS_SQL) {
subQuery = this.knex.raw(
`(SELECT a.* FROM (${subQuery}) AS a FOR JSON PATH)`
wrapperQuery = this.knex.raw(
`(SELECT [${toAlias}] = (SELECT a.* FROM (${subQuery}) AS a FOR JSON PATH))`
)
}
} else {
// @ts-ignore - the from alias syntax isn't in Knex typing
const wrapperQuery = this.knex.select(select).from({
wrapperQuery = this.knex.select(select).from({
[toAlias]: subQuery,
})
}
query = query.select({ [relationship.column]: wrapperQuery })
}
return query