Browse Source

Merge pull request #5609 from nocodb/fix/mm-column-drop

fix: drop mm table on column delete
pull/5621/head
Pranav C 2 years ago committed by GitHub
parent
commit
4d938f1f65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/nc-gui/components/smartsheet/header/Menu.vue
  2. 2
      packages/nocodb/src/services/columns.service.ts

11
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -14,9 +14,11 @@ import {
iconMap,
inject,
message,
useGlobal,
useI18n,
useMetas,
useNuxtApp,
useProject,
useSmartsheetStoreOrThrow,
useUndoRedo,
} from '#imports'
@ -28,6 +30,10 @@ const emit = defineEmits(['edit', 'addColumn'])
const { eventBus } = useSmartsheetStoreOrThrow()
const { includeM2M } = useGlobal()
const { loadTables } = useProject()
const column = inject(ColumnInj)
const reloadDataHook = inject(ReloadViewDataHookInj)
@ -62,6 +68,11 @@ const deleteColumn = () =>
/** force-reload related table meta if deleted column is a LTAR and not linked to same table */
if (column?.value?.uidt === UITypes.LinkToAnotherRecord && column.value?.colOptions) {
await getMeta((column.value?.colOptions as LinkToAnotherRecordType).fk_related_model_id!, true)
// reload tables if deleted column is mm and include m2m is true
if (includeM2M.value && (column.value?.colOptions as LinkToAnotherRecordType).type === RelationTypes.MANY_TO_MANY) {
loadTables()
}
}
$e('a:column:delete')

2
packages/nocodb/src/services/columns.service.ts

@ -1287,6 +1287,8 @@ export class ColumnsService {
// ignore deleting table if it has more than 2 columns
// the expected 2 columns would be table1_id & table2_id
if (mmTable.columns.length === 2) {
(mmTable as any).tn = mmTable.table_name;
await sqlMgr.sqlOpPlus(base, 'tableDelete', mmTable);
await mmTable.delete();
}
}

Loading…
Cancel
Save