fix: add default value for rollup

This commit is contained in:
DarkPhoenix2704
2024-09-11 08:46:13 +00:00
parent 936032881e
commit f7bf923e34

View File

@@ -58,9 +58,23 @@ export default async function ({
return;
}
qb[columnOptions.rollup_function as string]?.(
knex.ref(`${refTableAlias}.${rollupColumn.column_name}`),
);
if (
['sum', 'sumDistinct', 'avgDistinct', 'avg'].includes(
columnOptions.rollup_function,
)
) {
qb.select(
knex.raw(`COALESCE((??), 0)`, [
knex[columnOptions.rollup_function as string]?.(
knex.ref(`${refTableAlias}.${rollupColumn.column_name}`),
),
]),
);
} else {
qb[columnOptions.rollup_function as string]?.(
knex.ref(`${refTableAlias}.${rollupColumn.column_name}`),
);
}
};
switch (relationColumnOption.type) {