Browse Source

fix: multiple source project prefix

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3573/head
mertmit 2 years ago
parent
commit
743c160eef
  1. 2
      packages/nc-gui/composables/useTable.ts
  2. 7
      packages/nocodb/src/lib/meta/api/tableApis.ts
  3. 2
      packages/nocodb/src/lib/meta/helpers/getTableName.ts

2
packages/nc-gui/composables/useTable.ts

@ -63,7 +63,7 @@ export function useTable(onTableCreate?: (tableMeta: TableType) => void, baseId?
watch(
() => table.title,
(title) => {
table.table_name = `${project?.value?.prefix || ''}${title}`
table.table_name = `${title}`
},
)

7
packages/nocodb/src/lib/meta/api/tableApis.ts

@ -90,6 +90,7 @@ export async function tableList(req: Request, res: Response<TableListType>) {
export async function tableCreate(req: Request<any, any, TableReqType>, res) {
const project = await Project.getWithInfo(req.params.projectId);
let base = project.bases[0];
if (req.params.baseId) {
base = project.bases.find((b) => b.id === req.params.baseId);
}
@ -103,7 +104,7 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
);
}
if (project.prefix) {
if (base.is_meta && project.prefix) {
if (!req.body.table_name.startsWith(project.prefix)) {
req.body.table_name = `${project.prefix}_${req.body.table_name}`;
}
@ -228,14 +229,14 @@ export async function tableUpdate(req: Request<any, any>, res) {
const project = await Project.getWithInfo(req.body.project_id);
const base = project.bases.find((b) => b.id === model.base_id);
if (!req.body.table_name) {
NcError.badRequest(
'Missing table name `table_name` property in request body'
);
}
if (project.prefix) {
if (base.is_meta && project.prefix) {
if (!req.body.table_name.startsWith(project.prefix)) {
req.body.table_name = `${project.prefix}${req.body.table_name}`;
}

2
packages/nocodb/src/lib/meta/helpers/getTableName.ts

@ -7,7 +7,7 @@ export default function getTableNameAlias(
base: Base
): string {
let tn = tableName;
if (prefix) {
if (base.is_meta && prefix) {
tn = tn.replace(prefix, '');
}

Loading…
Cancel
Save