Avoid duplicates
This commit is contained in:
parent
4e8e725b4b
commit
c0e4168659
|
@ -66,6 +66,8 @@ async function generateTablesDelegate(data: ai.GenerationStructure) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const processedRelationships: string[] = []
|
||||||
|
|
||||||
for (const table of Object.values(data.tables)) {
|
for (const table of Object.values(data.tables)) {
|
||||||
const storedTable = await sdk.tables.getTable(tableIds[table.name])
|
const storedTable = await sdk.tables.getTable(tableIds[table.name])
|
||||||
|
|
||||||
|
@ -75,8 +77,12 @@ async function generateTablesDelegate(data: ai.GenerationStructure) {
|
||||||
...storedTable.schema,
|
...storedTable.schema,
|
||||||
...table.schema.reduce<TableSchema>((acc, field) => {
|
...table.schema.reduce<TableSchema>((acc, field) => {
|
||||||
if (field.type === FieldType.LINK) {
|
if (field.type === FieldType.LINK) {
|
||||||
|
// Avoid circular references
|
||||||
|
if (!processedRelationships.includes(field.relationshipId)) {
|
||||||
const { reverseFieldName, relationshipId, ...rest } = field
|
const { reverseFieldName, relationshipId, ...rest } = field
|
||||||
acc[field.name] = { ...rest, fieldName: reverseFieldName }
|
acc[field.name] = { ...rest, fieldName: reverseFieldName }
|
||||||
|
processedRelationships.push(relationshipId)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
acc[field.name] = field
|
acc[field.name] = field
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue