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] =
toRelationship
// If relationship has been renamed
if (originalFromName !== fromRelationship.name) {
delete datasource.entities[fromTable.name].schema[originalFromName]
// If relationship has been renamed or a different table selected
if (
originalFromTable?.name &&
(originalFromName !== fromRelationship.name ||
hasTableChanged(fromTable, toTable))
) {
delete datasource.entities[originalFromTable.name].schema[
originalFromName
]
}
if (originalToName !== toRelationship.name) {
delete datasource.entities[toTable.name].schema[originalToName]
if (
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