Remove existing relationships if table changed

This commit is contained in:
Mel O'Hagan 2023-01-13 18:14:34 +00:00
parent db29b131eb
commit 30905d35ef
1 changed files with 15 additions and 5 deletions

View File

@ -245,12 +245,22 @@
datasource.entities[toTable.name].schema[toRelationship.name] = datasource.entities[toTable.name].schema[toRelationship.name] =
toRelationship toRelationship
// If relationship has been renamed // If relationship has been renamed or a different table selected
if (originalFromName !== fromRelationship.name) { if (
delete datasource.entities[fromTable.name].schema[originalFromName] originalFromTable?.name &&
(originalFromName !== fromRelationship.name ||
hasTableChanged(fromTable, toTable))
) {
delete datasource.entities[originalFromTable.name].schema[
originalFromName
]
} }
if (originalToName !== toRelationship.name) { if (
delete datasource.entities[toTable.name].schema[originalToName] originalToTable?.name &&
(originalToName !== toRelationship.name ||
hasTableChanged(fromTable, toTable))
) {
delete datasource.entities[originalToTable.name].schema[originalToName]
} }
// store the original names so it won't cause an error // store the original names so it won't cause an error