Cleaning up how junction fields are added to query.

This commit is contained in:
mike12345567 2024-07-09 16:32:35 +01:00
parent 396de67aea
commit 6e699a163d
1 changed files with 8 additions and 12 deletions

View File

@ -59,6 +59,13 @@ function buildInternalFieldList(
opts?: { relationships?: RelationshipsJson[] } opts?: { relationships?: RelationshipsJson[] }
) { ) {
let fieldList: string[] = [] let fieldList: string[] = []
const addJunctionFields = (relatedTable: Table, fields: string[]) => {
fields.forEach(field => {
fieldList.push(
`${generateJunctionTableID(table._id!, relatedTable._id!)}.${field}`
)
})
}
fieldList = fieldList.concat( fieldList = fieldList.concat(
CONSTANT_INTERNAL_ROW_COLS.map(col => `${table._id}.${col}`) CONSTANT_INTERNAL_ROW_COLS.map(col => `${table._id}.${col}`)
) )
@ -72,18 +79,7 @@ function buildInternalFieldList(
const relatedTable = tables.find(table => table._id === linkCol.tableId)! const relatedTable = tables.find(table => table._id === linkCol.tableId)!
// no relationships provided, don't go more than a layer deep // no relationships provided, don't go more than a layer deep
fieldList = fieldList.concat(buildInternalFieldList(relatedTable, tables)) fieldList = fieldList.concat(buildInternalFieldList(relatedTable, tables))
fieldList.push( addJunctionFields(relatedTable, ["doc1.fieldName", "doc2.fieldName"])
`${generateJunctionTableID(
table._id!,
relatedTable._id!
)}.doc1.fieldName`
)
fieldList.push(
`${generateJunctionTableID(
table._id!,
relatedTable._id!
)}.doc2.fieldName`
)
} else { } else {
fieldList.push(`${table._id}.${mapToUserColumn(col.name)}`) fieldList.push(`${table._id}.${mapToUserColumn(col.name)}`)
} }