Browse Source

wip: hasLTARData logic for M2M

pull/2608/head
Wing-Kam Wong 3 years ago
parent
commit
8b5598ccb9
  1. 40
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

40
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1380,6 +1380,46 @@ class BaseModelSqlv2 {
}
}
async hasLTARData(rowId, model: Model): Promise<any> {
const LTARColumns = (await model.getColumns()).filter(
(c) => c.uidt === UITypes.LinkToAnotherRecord
);
const res = [];
for (const column of LTARColumns) {
const colOptions =
(await column.getColOptions()) as LinkToAnotherRecordColumn;
const childColumn = await colOptions.getChildColumn();
const parentColumn = await colOptions.getParentColumn();
const childModel = await childColumn.getModel();
await childModel.getColumns();
const parentModel = await parentColumn.getModel();
await parentModel.getColumns();
let i = 0;
if (colOptions.type === RelationTypes.HAS_MANY) {
// TODO:
continue;
} else if (colOptions.type === RelationTypes.BELONGS_TO) {
// TODO:
continue;
} else if (colOptions.type === RelationTypes.MANY_TO_MANY) {
const mmModel = await colOptions.getMMModel();
const mmChildColumn = await colOptions.getMMChildColumn();
const selectMmCount = await this.dbDriver(mmModel.table_name)
.where(`${mmModel.table_name}.${mmChildColumn.column_name}`, rowId)
.count(mmChildColumn.column_name, { as: 'cnt' });
const cnt = (await selectMmCount)[0].cnt;
if (cnt) {
res.push(
`${i++ + 1}. ${model.title}.${
column.title
} is a LinkToAnotherRecord of ${parentModel.title}`
);
}
}
}
return res;
}
async updateByPk(id, data, trx?, cookie?) {
try {
const updateObj = await this.model.mapAliasToColumn(data);

Loading…
Cancel
Save