Merge pull request #14413 from Budibase/fix/missing-table-definition-search
SQS - broken relationship fix
This commit is contained in:
commit
cb67a24a13
|
@ -151,7 +151,10 @@ export function buildExternalRelationships(
|
||||||
return relationships
|
return relationships
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildInternalRelationships(table: Table): RelationshipsJson[] {
|
export function buildInternalRelationships(
|
||||||
|
table: Table,
|
||||||
|
allTables: Table[]
|
||||||
|
): RelationshipsJson[] {
|
||||||
const relationships: RelationshipsJson[] = []
|
const relationships: RelationshipsJson[] = []
|
||||||
const links = Object.values(table.schema).filter(
|
const links = Object.values(table.schema).filter(
|
||||||
column => column.type === FieldType.LINK
|
column => column.type === FieldType.LINK
|
||||||
|
@ -164,6 +167,10 @@ export function buildInternalRelationships(table: Table): RelationshipsJson[] {
|
||||||
const linkTableId = link.tableId!
|
const linkTableId = link.tableId!
|
||||||
const junctionTableId = generateJunctionTableID(tableId, linkTableId)
|
const junctionTableId = generateJunctionTableID(tableId, linkTableId)
|
||||||
const isFirstTable = tableId > linkTableId
|
const isFirstTable = tableId > linkTableId
|
||||||
|
// skip relationships with missing table definitions
|
||||||
|
if (!allTables.find(table => table._id === linkTableId)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
relationships.push({
|
relationships.push({
|
||||||
through: junctionTableId,
|
through: junctionTableId,
|
||||||
column: link.name,
|
column: link.name,
|
||||||
|
|
|
@ -71,6 +71,7 @@ export const getQueryableFields = async (
|
||||||
// avoid circular loops
|
// avoid circular loops
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const relatedTable = await sdk.tables.getTable(subSchema.tableId)
|
const relatedTable = await sdk.tables.getTable(subSchema.tableId)
|
||||||
const relatedFields = await extractTableFields(
|
const relatedFields = await extractTableFields(
|
||||||
relatedTable,
|
relatedTable,
|
||||||
|
@ -85,6 +86,12 @@ export const getQueryableFields = async (
|
||||||
`${relatedTable.name}.${f}`,
|
`${relatedTable.name}.${f}`,
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
} catch (err: any) {
|
||||||
|
// if related table is removed, ignore
|
||||||
|
if (err.status !== 404) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push(field)
|
result.push(field)
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ export async function search(
|
||||||
throw new Error("Unable to find table")
|
throw new Error("Unable to find table")
|
||||||
}
|
}
|
||||||
|
|
||||||
const relationships = buildInternalRelationships(table)
|
const relationships = buildInternalRelationships(table, allTables)
|
||||||
|
|
||||||
const searchFilters: SearchFilters = {
|
const searchFilters: SearchFilters = {
|
||||||
...cleanupFilters(query, table, allTables),
|
...cleanupFilters(query, table, allTables),
|
||||||
|
|
Loading…
Reference in New Issue