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. 5
      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( watch(
() => table.title, () => table.title,
(title) => { (title) => {
table.table_name = `${project?.value?.prefix || ''}${title}` table.table_name = `${title}`
}, },
) )

5
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) { export async function tableCreate(req: Request<any, any, TableReqType>, res) {
const project = await Project.getWithInfo(req.params.projectId); const project = await Project.getWithInfo(req.params.projectId);
let base = project.bases[0]; let base = project.bases[0];
if (req.params.baseId) { if (req.params.baseId) {
base = project.bases.find((b) => b.id === 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)) { if (!req.body.table_name.startsWith(project.prefix)) {
req.body.table_name = `${project.prefix}_${req.body.table_name}`; req.body.table_name = `${project.prefix}_${req.body.table_name}`;
} }
@ -235,7 +236,7 @@ export async function tableUpdate(req: Request<any, any>, res) {
); );
} }
if (project.prefix) { if (base.is_meta && project.prefix) {
if (!req.body.table_name.startsWith(project.prefix)) { if (!req.body.table_name.startsWith(project.prefix)) {
req.body.table_name = `${project.prefix}${req.body.table_name}`; 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 base: Base
): string { ): string {
let tn = tableName; let tn = tableName;
if (prefix) { if (base.is_meta && prefix) {
tn = tn.replace(prefix, ''); tn = tn.replace(prefix, '');
} }

Loading…
Cancel
Save