Browse Source

fix: extract foreign key name if LTAR colopt is not provided

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

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

@ -1754,6 +1754,31 @@ const deleteHmOrBtRelation = async (
}, },
ignoreFkDelete = false ignoreFkDelete = false
) => { ) => {
let foreignKeyName;
// if relationColOpt is not provided, extract it from child table
// and get the foreign key name for dropping the foreign key
if (!relationColOpt) {
foreignKeyName = (
(
await childTable.getColumns().then((cols) => {
return cols?.find((c) => {
return (
c.uidt === UITypes.LinkToAnotherRecord &&
c.colOptions.fk_related_model_id === parentTable.id &&
(c.colOptions as LinkToAnotherRecordType).fk_child_column_id ===
childColumn.id &&
(c.colOptions as LinkToAnotherRecordType).fk_parent_column_id ===
parentColumn.id
);
});
})
).colOptions as LinkToAnotherRecordType
).fk_index_name;
} else {
foreignKeyName = relationColOpt.fk_index_name;
}
// todo: handle relation delete exception // todo: handle relation delete exception
try { try {
await sqlMgr.sqlOpPlus(base, 'relationDelete', { await sqlMgr.sqlOpPlus(base, 'relationDelete', {
@ -1761,7 +1786,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: relationColOpt.fk_index_name, foreignKeyName,
}); });
} catch (e) { } catch (e) {
console.log(e); console.log(e);

Loading…
Cancel
Save