Browse Source

fix: map count import to rollup properly

pull/7439/head
mertmit 11 months ago
parent
commit
a6d746556e
  1. 28
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

28
packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

@ -522,7 +522,7 @@ export class AtImportProcessor {
const col = tblSchema[i].columns[j]; const col = tblSchema[i].columns[j];
// skip link, lookup, rollup fields in this iteration // skip link, lookup, rollup fields in this iteration
if (['foreignKey', 'lookup', 'rollup'].includes(col.type)) { if (['foreignKey', 'lookup', 'rollup', 'count'].includes(col.type)) {
continue; continue;
} }
@ -1100,7 +1100,7 @@ export class AtImportProcessor {
CONCATENATE: '', CONCATENATE: '',
COUNT: 'count', COUNT: 'count',
COUNTA: '', COUNTA: '',
COUNTALL: '', COUNTALL: 'count',
MAX: 'max', MAX: 'max',
MIN: 'min', MIN: 'min',
OR: '', OR: '',
@ -1114,7 +1114,7 @@ export class AtImportProcessor {
// Rollup // Rollup
for (let idx = 0; idx < aTblSchema.length; idx++) { for (let idx = 0; idx < aTblSchema.length; idx++) {
const aTblColumns = aTblSchema[idx].columns.filter( const aTblColumns = aTblSchema[idx].columns.filter(
(x) => x.type === 'rollup', (x) => x.type === 'rollup' || x.type === 'count',
); );
// parent table ID // parent table ID
@ -1132,7 +1132,10 @@ export class AtImportProcessor {
// fetch associated rollup function // fetch associated rollup function
// skip column creation if supported rollup function does not exist // skip column creation if supported rollup function does not exist
const ncRollupFn = getRollupNcFunction( const ncRollupFn =
aTblColumns[i].type === 'count'
? 'count'
: getRollupNcFunction(
aTblColumns[i].typeOptions.formulaTextParsed, aTblColumns[i].typeOptions.formulaTextParsed,
); );
@ -1166,10 +1169,23 @@ export class AtImportProcessor {
const ncRelationColumnId = await sMap.getNcIdFromAtId( const ncRelationColumnId = await sMap.getNcIdFromAtId(
aTblColumns[i].typeOptions.relationColumnId, aTblColumns[i].typeOptions.relationColumnId,
); );
const ncRollupColumnId = await sMap.getNcIdFromAtId( let ncRollupColumnId = await sMap.getNcIdFromAtId(
aTblColumns[i].typeOptions.foreignTableRollupColumnId, aTblColumns[i].typeOptions.foreignTableRollupColumnId,
); );
if (!ncRollupColumnId && aTblColumns[i].type === 'count') {
const ncRelationColumn = await nc_getColumnSchema(
aTblColumns[i].typeOptions.relationColumnId,
);
const ncRelatedModelId =
ncRelationColumn?.colOptions?.fk_related_model_id;
if (ncRelatedModelId) {
ncRollupColumnId = ncSchema.tablesById[
ncRelatedModelId
].columns.find((x) => x.pk)?.id;
}
}
if (!ncRollupColumnId) { if (!ncRollupColumnId) {
aTblColumns[i]['srcTableId'] = srcTableId; aTblColumns[i]['srcTableId'] = srcTableId;
nestedRollupTbl.push(aTblColumns[i]); nestedRollupTbl.push(aTblColumns[i]);
@ -1884,7 +1900,7 @@ export class AtImportProcessor {
(x) => x.type === 'lookup', (x) => x.type === 'lookup',
); );
const aTblRollup = aTblSchema[idx].columns.filter( const aTblRollup = aTblSchema[idx].columns.filter(
(x) => x.type === 'rollup', (x) => x.type === 'rollup' || x.type === 'count',
); );
let invalidColumnId = 0; let invalidColumnId = 0;

Loading…
Cancel
Save