Browse Source

fix: avoid deleting foreign key when it's a custom link

pull/8367/head
Pranav C 5 months ago
parent
commit
f3381252ff
  1. 19
      packages/nc-gui/components/smartsheet/column/LinkAdvancedOptions.vue
  2. 14
      packages/nocodb/src/helpers/columnHelpers.ts

19
packages/nc-gui/components/smartsheet/column/LinkAdvancedOptions.vue

@ -1,6 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { useColumnCreateStoreOrThrow, useVModel, computed, inject, MetaInj, ref, useI18n,useBase, storeToRefs, useMetas } from '#imports' import { useColumnCreateStoreOrThrow, useVModel, computed, inject, MetaInj, ref, useI18n,useBase, storeToRefs, useMetas } from '#imports'
import {isVirtualCol, ModelTypes, RelationTypes, UITypes} from "nocodb-sdk"; import {
isCreatedOrLastModifiedByCol,
isCreatedOrLastModifiedTimeCol,
isVirtualCol,
ModelTypes,
RelationTypes,
UITypes
} from "nocodb-sdk";
import type {ColumnType} from "nocodb-sdk"; import type {ColumnType} from "nocodb-sdk";
const props = defineProps<{ const props = defineProps<{
@ -46,7 +53,7 @@ const columns = computed(() => {
return [] return []
} }
return meta.value.columns; return meta.value.columns?.filter(c => !isCreatedOrLastModifiedByCol(c) && !isCreatedOrLastModifiedTimeCol(c) && !isVirtualCol(c));
}) })
const refTableColumns = computed(() => { const refTableColumns = computed(() => {
@ -55,9 +62,7 @@ const refTableColumns = computed(() => {
} }
return metas.value[vModel.value.custom?.ref_model_id]?.columns.filter( return metas.value[vModel.value.custom?.ref_model_id]?.columns?.filter(c => !isCreatedOrLastModifiedByCol(c) && !isCreatedOrLastModifiedTimeCol(c) && !isVirtualCol(c))
(c: ColumnType) => !isVirtualCol(c.uidt as UITypes),
)
}) })
const juncTableColumns = computed(() => { const juncTableColumns = computed(() => {
@ -66,9 +71,7 @@ const juncTableColumns = computed(() => {
} }
return metas.value[vModel.value.custom?.junc_model_id]?.columns.filter( return metas.value[vModel.value.custom?.junc_model_id]?.columns?.filter(c => !isCreatedOrLastModifiedByCol(c) && !isCreatedOrLastModifiedTimeCol(c) && !isVirtualCol(c))
(c: ColumnType) => !isVirtualCol(c.uidt as UITypes),
)
}) })

14
packages/nocodb/src/helpers/columnHelpers.ts

@ -44,7 +44,7 @@ export async function createHmAndBtColumn(
isLinks = false, isLinks = false,
colExtra?: any, colExtra?: any,
parentColumn?: Column, parentColumn?: Column,
isCustom = false isCustom = false,
) { ) {
// save bt column // save bt column
{ {
@ -72,8 +72,8 @@ export async function createHmAndBtColumn(
...(type === 'bt' ? colExtra : {}), ...(type === 'bt' ? colExtra : {}),
meta: { meta: {
...(colExtra?.meta || {}), ...(colExtra?.meta || {}),
custom: isCustom custom: isCustom,
} },
}); });
} }
// save hm column // save hm column
@ -86,7 +86,7 @@ export async function createHmAndBtColumn(
...(columnMeta || {}), ...(columnMeta || {}),
plural: columnMeta?.plural || pluralize(child.title), plural: columnMeta?.plural || pluralize(child.title),
singular: columnMeta?.singular || singularize(child.title), singular: columnMeta?.singular || singularize(child.title),
custom: isCustom custom: isCustom,
}; };
await Column.insert(context, { await Column.insert(context, {
@ -136,7 +136,7 @@ export async function createOOColumn(
columnMeta = null, columnMeta = null,
colExtra?: any, colExtra?: any,
parentColumn?: Column, parentColumn?: Column,
isCustom = false isCustom = false,
) { ) {
// save bt column // save bt column
{ {
@ -166,7 +166,7 @@ export async function createOOColumn(
// one-to-one relation is combination of both hm and bt to identify table which have // one-to-one relation is combination of both hm and bt to identify table which have
// foreign key column(similar to bt) we are adding a boolean flag `bt` under meta // foreign key column(similar to bt) we are adding a boolean flag `bt` under meta
bt: true, bt: true,
custom: isCustom custom: isCustom,
}, },
}); });
} }
@ -186,7 +186,7 @@ export async function createOOColumn(
...(columnMeta || {}), ...(columnMeta || {}),
plural: columnMeta?.plural || pluralize(child.title), plural: columnMeta?.plural || pluralize(child.title),
singular: columnMeta?.singular || singularize(child.title), singular: columnMeta?.singular || singularize(child.title),
custom: isCustom custom: isCustom,
}; };
await Column.insert(context, { await Column.insert(context, {

Loading…
Cancel
Save