Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: restore ONE_TO_ONE case and mmModel null check in genRollupSelectv2

Pranav52dda30a53ba
diff --git a/packages/nocodb/src/db/genRollupSelectv2.ts b/packages/nocodb/src/db/genRollupSelectv2.ts
index 97ae92027b..ea9af7bfe4 100644
--- a/packages/nocodb/src/db/genRollupSelectv2.ts
+++ b/packages/nocodb/src/db/genRollupSelectv2.ts
@@ -1,4 +1,4 @@
-import { isMMOrMMLike, RelationTypes, UITypes } from 'nocodb-sdk';
+import { isMMOrMMLike, NcDataErrorCodes, RelationTypes, UITypes } from 'nocodb-sdk';
import { CircularRefContext } from 'nocodb-sdk';
import type { IBaseModelSqlV2 } from './IBaseModelSqlV2';
import type { Knex } from 'knex';
@@ -224,10 +224,6 @@ export default async function genRollupSelectv2(param: {
const relationType = isMMLike
? RelationTypes.MANY_TO_MANY
- : relationColumnOption.type === RelationTypes.ONE_TO_ONE
- ? relationColumn.meta?.bt
- ? 'bt'
- : 'hm'
: relationColumnOption.type;
switch (relationType) {
@@ -265,6 +261,39 @@ export default async function genRollupSelectv2(param: {
};
}
+ case RelationTypes.ONE_TO_ONE: {
+ profiler.log('Relation: ' + relationColumnOption.type);
+ const qb = knex(
+ knex.raw(`?? as ??`, [
+ childBaseModel.getTnPath(childModel?.table_name),
+ refTableAlias,
+ ]),
+ ).where(
+ knex.ref(
+ `${alias || parentBaseModel.getTnPath(parentModel.table_name)}.${
+ parentCol.column_name
+ }`,
+ ),
+ '=',
+ knex.ref(`${refTableAlias}.${childCol.column_name}`),
+ );
+
+ await extractLinkRelFiltersAndApply({
+ qb,
+ column,
+ alias: refTableAlias,
+ table: childBaseModel.model,
+ baseModel: childBaseModel,
+ context: childBaseModel.context,
+ });
+
+ await applyFunction(qb);
+ profiler.end();
+ return {
+ builder: qb,
+ };
+ }
+
case RelationTypes.MANY_TO_MANY: {
profiler.log('Relation: ' + relationColumnOption.type);
const mmModel = await relationColumnOption.getMMModel(mmContext);
@@ -276,6 +305,11 @@ export default async function genRollupSelectv2(param: {
id: mmModel.id,
dbDriver: knex,
});
+ if (!mmModel) {
+ return this.dbDriver.raw(`?`, [
+ NcDataErrorCodes.NC_ERR_MM_MODEL_NOT_FOUND,
+ ]);
+ }
const qb = knex(
knex.raw(`?? as ??`, [