Revert relationship changes

This commit is contained in:
Adria Navarro 2023-09-13 12:02:13 +02:00
parent 823afa1f55
commit ceb3129e22
1 changed files with 7 additions and 9 deletions

View File

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