Browse Source

feat: use better junction table name and column names

pull/9733/head
Pranav C 4 weeks ago
parent
commit
7c165511a1
  1. 18
      packages/nocodb/src/services/columns.service.ts

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

@ -135,6 +135,18 @@ async function reuseOrSave(
return res; return res;
} }
function getJunctionTableName(
param: {
base: Base;
},
parent: Model,
child: Model,
) {
return `${param.base?.prefix ?? ''}_nc_m2m_${parent.table_name}_${
child.table_name
}`;
}
@Injectable() @Injectable()
export class ColumnsService { export class ColumnsService {
constructor( constructor(
@ -3266,7 +3278,7 @@ export class ColumnsService {
param.colExtra, param.colExtra,
); );
} else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') { } else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') {
const aTn = `${param.base?.prefix ?? ''}_nc_m2m_${randomID()}`; const aTn = getJunctionTableName(param, parent, child);
const aTnAlias = aTn; const aTnAlias = aTn;
const parentPK = parent.primaryKey; const parentPK = parent.primaryKey;
@ -3274,8 +3286,8 @@ export class ColumnsService {
const associateTableCols = []; const associateTableCols = [];
const parentCn = 'table1_id'; const parentCn = `${parent.table_name}_id`;
const childCn = 'table2_id'; const childCn = `${child.table_name}_id`;
associateTableCols.push( associateTableCols.push(
{ {

Loading…
Cancel
Save