Browse Source

fix(gui): specify constraint name while deleting relation

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5030/head
Pranav C 2 years ago
parent
commit
72f8a7059f
  1. 22
      packages/nocodb/src/lib/meta/api/columnApis.ts

22
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -69,6 +69,7 @@ async function createHmAndBtColumn(
childColumn: Column, childColumn: Column,
type?: RelationTypes, type?: RelationTypes,
alias?: string, alias?: string,
fkColName?: string,
virtual = false, virtual = false,
isSystemCol = false isSystemCol = false
) { ) {
@ -92,6 +93,7 @@ async function createHmAndBtColumn(
fk_related_model_id: parent.id, fk_related_model_id: parent.id,
virtual, virtual,
system: isSystemCol, system: isSystemCol,
fk_col_name: fkColName,
}); });
} }
// save hm column // save hm column
@ -110,6 +112,7 @@ async function createHmAndBtColumn(
fk_related_model_id: child.id, fk_related_model_id: child.id,
virtual, virtual,
system: isSystemCol, system: isSystemCol,
fk_col_name: fkColName,
}); });
} }
} }
@ -318,8 +321,10 @@ export async function columnAdd(
childColumn = await Column.get({ colId: id }); childColumn = await Column.get({ colId: id });
let foreignKeyName;
// ignore relation creation if virtual // ignore relation creation if virtual
if (!(req.body as LinkToAnotherColumnReqType).virtual) { if (!(req.body as LinkToAnotherColumnReqType).virtual) {
foreignKeyName = generateFkConstraintName(parent, child);
// create relation // create relation
await sqlMgr.sqlOpPlus(base, 'relationCreate', { await sqlMgr.sqlOpPlus(base, 'relationCreate', {
childColumn: fkColName, childColumn: fkColName,
@ -329,7 +334,7 @@ export async function columnAdd(
onUpdate: 'NO ACTION', onUpdate: 'NO ACTION',
type: 'real', type: 'real',
parentColumn: parent.primaryKey.column_name, parentColumn: parent.primaryKey.column_name,
foreignKeyName: generateFkConstraintName(parent, child), foreignKeyName,
}); });
} }
@ -352,6 +357,7 @@ export async function columnAdd(
childColumn, childColumn,
(req.body as LinkToAnotherColumnReqType).type as RelationTypes, (req.body as LinkToAnotherColumnReqType).type as RelationTypes,
(req.body as LinkToAnotherColumnReqType).title, (req.body as LinkToAnotherColumnReqType).title,
fkColName,
(req.body as LinkToAnotherColumnReqType).virtual (req.body as LinkToAnotherColumnReqType).virtual
); );
} else if ((req.body as LinkToAnotherColumnReqType).type === 'mm') { } else if ((req.body as LinkToAnotherColumnReqType).type === 'mm') {
@ -413,7 +419,13 @@ export async function columnAdd(
columns: associateTableCols, columns: associateTableCols,
}); });
let foreignKeyName1;
let foreignKeyName2;
if (!(req.body as LinkToAnotherColumnReqType).virtual) { if (!(req.body as LinkToAnotherColumnReqType).virtual) {
foreignKeyName1 = generateFkConstraintName(parent, child);
foreignKeyName2 = generateFkConstraintName(parent, child);
const rel1Args = { const rel1Args = {
...req.body, ...req.body,
childTable: aTn, childTable: aTn,
@ -421,7 +433,7 @@ export async function columnAdd(
parentTable: parent.table_name, parentTable: parent.table_name,
parentColumn: parentPK.column_name, parentColumn: parentPK.column_name,
type: 'real', type: 'real',
foreignKeyName: generateFkConstraintName(parent, child), foreignKeyName: foreignKeyName1,
}; };
const rel2Args = { const rel2Args = {
...req.body, ...req.body,
@ -430,7 +442,7 @@ export async function columnAdd(
parentTable: child.table_name, parentTable: child.table_name,
parentColumn: childPK.column_name, parentColumn: childPK.column_name,
type: 'real', type: 'real',
foreignKeyName: generateFkConstraintName(parent, child), foreignKeyName: foreignKeyName2,
}; };
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args);
@ -449,6 +461,7 @@ export async function columnAdd(
childCol, childCol,
null, null,
null, null,
foreignKeyName1,
(req.body as LinkToAnotherColumnReqType).virtual, (req.body as LinkToAnotherColumnReqType).virtual,
true true
); );
@ -458,6 +471,7 @@ export async function columnAdd(
parentCol, parentCol,
null, null,
null, null,
foreignKeyName2,
(req.body as LinkToAnotherColumnReqType).virtual, (req.body as LinkToAnotherColumnReqType).virtual,
true true
); );
@ -1747,7 +1761,7 @@ const deleteHmOrBtRelation = async (
childTable: childTable.table_name, childTable: childTable.table_name,
parentTable: parentTable.table_name, parentTable: parentTable.table_name,
parentColumn: parentColumn.column_name, parentColumn: parentColumn.column_name,
// foreignKeyName: relation.fkn foreignKeyName: relationColOpt.fk_index_name,
}); });
} catch (e) { } catch (e) {
console.log(e); console.log(e);

Loading…
Cancel
Save