Add back cte
This commit is contained in:
parent
0ef4a154ef
commit
fc22db35ac
|
@ -1604,8 +1604,17 @@ class InternalBuilder {
|
||||||
|
|
||||||
// handle relationships with a CTE for all others
|
// handle relationships with a CTE for all others
|
||||||
if (relationships?.length && aggregations.length === 0) {
|
if (relationships?.length && aggregations.length === 0) {
|
||||||
|
const mainTable = this.query.tableAliases?.[table.name] || table.name
|
||||||
|
const cte = this.addSorting(
|
||||||
|
this.knex
|
||||||
|
.with("paginated", query.clone().clearSelect().select("*"))
|
||||||
|
.select(this.generateSelectStatement())
|
||||||
|
.from({
|
||||||
|
[mainTable]: "paginated",
|
||||||
|
})
|
||||||
|
)
|
||||||
// add JSON aggregations attached to the CTE
|
// add JSON aggregations attached to the CTE
|
||||||
return this.addJsonRelationships(query, table.name, relationships)
|
return this.addJsonRelationships(cte, table.name, relationships)
|
||||||
}
|
}
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -161,15 +161,14 @@ export async function buildSqlFieldList(
|
||||||
let table: Table
|
let table: Table
|
||||||
if (isView) {
|
if (isView) {
|
||||||
table = await sdk.views.getTable(source.id)
|
table = await sdk.views.getTable(source.id)
|
||||||
fields = fields.filter(f => table.schema[f].type !== FieldType.LINK)
|
|
||||||
} else {
|
} else {
|
||||||
table = source
|
table = source
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isView) {
|
if (isView) {
|
||||||
fields = Object.keys(helpers.views.basicFields(source)).map(
|
fields = Object.keys(helpers.views.basicFields(source))
|
||||||
c => `${table.name}.${c}`
|
.filter(f => table.schema[f].type !== FieldType.LINK)
|
||||||
)
|
.map(c => `${table.name}.${c}`)
|
||||||
} else {
|
} else {
|
||||||
fields = extractRealFields(source)
|
fields = extractRealFields(source)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue