Relations, select only required fields
This commit is contained in:
parent
583fb7505e
commit
3d767d52c0
|
@ -164,8 +164,24 @@ export async function buildSqlFieldList(
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tableName } = breakExternalTableId(field.tableId)
|
const { tableName } = breakExternalTableId(field.tableId)
|
||||||
if (tables[tableName]) {
|
const relatedTable = tables[tableName]
|
||||||
fields = fields.concat(extractRealFields(tables[tableName], fields))
|
if (relatedTable) {
|
||||||
|
const viewFields = new Set<string>()
|
||||||
|
relatedTable.primary?.forEach(f => viewFields.add(f))
|
||||||
|
if (relatedTable.primaryDisplay) {
|
||||||
|
viewFields.add(relatedTable.primaryDisplay)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isView) {
|
||||||
|
Object.entries(source.schema?.[field.name].columns || {})
|
||||||
|
.filter(([_, column]) => helpers.views.isVisible(column))
|
||||||
|
.forEach(([field]) => viewFields.add(field))
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldsToAdd = Array.from(viewFields)
|
||||||
|
.map(f => `${relatedTable.name}.${f}`)
|
||||||
|
.filter(f => !fields.includes(f))
|
||||||
|
fields.push(...fieldsToAdd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue