1
0
Fork 0
mirror of synced 2024-08-09 15:17:57 +12:00

Revert relationship changes

This commit is contained in:
Adria Navarro 2023-09-13 12:02:13 +02:00
parent 823afa1f55
commit ceb3129e22

View file

@ -67,15 +67,13 @@ function cleanupRelationships(
tables: Record<string, Table>,
oldTable?: Table
) {
const isUpdate = !!oldTable
if (!isUpdate) {
return
}
// When updating a table, we want to detect if some relationships were removed.
// If so, we want to remove the relationship from the other end
for (let [key, schema] of Object.entries(oldTable.schema)) {
if (schema.type === FieldTypes.LINK && !table.schema[key]) {
const tableToIterate = oldTable ? oldTable : table
// clean up relationships in couch table schemas
for (let [key, schema] of Object.entries(tableToIterate.schema)) {
if (
schema.type === FieldTypes.LINK &&
(!oldTable || table.schema[key] == null)
) {
const relatedTable = Object.values(tables).find(
table => table._id === schema.tableId
)