Browse Source

fix: avoid clashing names for fk & bt

pull/8371/head
mertmit 7 months ago
parent
commit
72149753f9
  1. 7
      packages/nocodb/src/helpers/getUniqueName.ts
  2. 9
      packages/nocodb/src/helpers/populateMeta.ts

7
packages/nocodb/src/helpers/getUniqueName.ts

@ -1,6 +1,9 @@
import type Column from '~/models/Column';
export function getUniqueColumnName(columns: Column[], initialName = 'field') {
export function getUniqueColumnName(
columns: Partial<Column>[],
initialName = 'field',
) {
let c = 0;
while (
@ -13,7 +16,7 @@ export function getUniqueColumnName(columns: Column[], initialName = 'field') {
}
export function getUniqueColumnAliasName(
columns: Column[],
columns: Partial<Column>[],
initialName = 'field',
) {
let c = 0;

9
packages/nocodb/src/helpers/populateMeta.ts

@ -2,7 +2,7 @@ import { ModelTypes, UITypes, ViewTypes } from 'nocodb-sdk';
import { isVirtualCol, RelationTypes } from 'nocodb-sdk';
import { pluralize, singularize } from 'inflection';
import { isLinksOrLTAR } from 'nocodb-sdk';
import { getUniqueColumnAliasName } from './getUniqueName';
import { getUniqueColumnAliasName, getUniqueColumnName } from './getUniqueName';
import type { RollupColumn } from '~/models';
import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn';
import type Source from '~/models/Source';
@ -383,8 +383,11 @@ export async function populateMeta(
base_id: base.id,
db_alias: source.id,
fk_model_id: models2[table.tn].id,
cn: column.cn,
title: column.title,
cn: getUniqueColumnName(models2[table.tn].columns, column.cn),
title: getUniqueColumnAliasName(
models2[table.tn].columns,
column.title,
),
uidt: column.uidt,
type: column.hm ? 'hm' : column.mm ? 'mm' : 'bt',
// column_id,

Loading…
Cancel
Save