Browse Source

fix: group by related fixes

pull/7304/head
Pranav C 12 months ago
parent
commit
b80d77bc1d
  1. 25
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 6
      packages/nocodb/src/db/conditionV2.ts
  3. 2
      packages/nocodb/src/db/generateLookupSelectQuery.ts

25
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -8,6 +8,7 @@ import { nocoExecute } from 'nc-help';
import {
AuditOperationSubTypes,
AuditOperationTypes,
isCreatedTimeOrUpdatedTimeCol,
isLinksOrLTAR,
isSystemColumn,
isVirtualCol,
@ -102,7 +103,9 @@ function checkColumnRequired(
}
export async function getColumnName(column: Column<any>, columns?: Column[]) {
if (!isCreatedTimeOrUpdatedTimeCol(column)) return column.column_name;
columns = columns || (await Column.list({ fk_model_id: column.fk_model_id }));
switch (column.uidt) {
case UITypes.CreatedTime: {
const createdTimeSystemCol = columns.find(
@ -664,10 +667,13 @@ class BaseModelSqlv2 {
}
break;
default:
selectors.push(
this.dbDriver.raw('?? as ??', [column.column_name, column.id]),
);
groupBySelectors.push(sanitize(column.id));
{
const columnName = await getColumnName(column, cols);
selectors.push(
this.dbDriver.raw('?? as ??', [columnName, column.id]),
);
groupBySelectors.push(sanitize(column.id));
}
break;
}
}),
@ -872,10 +878,13 @@ class BaseModelSqlv2 {
}
break;
default:
selectors.push(
this.dbDriver.raw('?? as ??', [column.column_name, column.id]),
);
groupBySelectors.push(sanitize(column.id));
{
const columnName = await getColumnName(column, cols);
selectors.push(
this.dbDriver.raw('?? as ??', [columnName, column.id]),
);
groupBySelectors.push(sanitize(column.id));
}
break;
}
}),

6
packages/nocodb/src/db/conditionV2.ts

@ -13,6 +13,7 @@ import type Column from '~/models/Column';
import type LookupColumn from '~/models/LookupColumn';
import type RollupColumn from '~/models/RollupColumn';
import type FormulaColumn from '~/models/FormulaColumn';
import { getColumnName } from '~/db/BaseModelSqlv2';
import { type BarcodeColumn, BaseUser, type QrCodeColumn } from '~/models';
import { NcError } from '~/helpers/catchError';
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2';
@ -544,6 +545,9 @@ const parseConditionV2 = async (
);
const _val = customWhereClause ? customWhereClause : filter.value;
// get column name for CreateTime, LastModifiedTime
column.column_name = await getColumnName(column);
return (qb: Knex.QueryBuilder) => {
let [field, val] = [_field, _val];
@ -678,7 +682,7 @@ const parseConditionV2 = async (
].includes(column.uidt)
) {
if (qb.client.config.client === 'pg') {
qb = qb.where(knex.raw('??::date = ?', [field, val]));
qb = qb.where(knex.raw('??::timestamp = ?', [field, val]));
} else {
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
}

2
packages/nocodb/src/db/generateLookupSelectQuery.ts

@ -312,6 +312,8 @@ export default async function generateLookupSelectQuery({
}
break;
case UITypes.DateTime:
case UITypes.LastModifiedTime:
case UITypes.CreatedTime:
{
await baseModelSqlv2.selectObject({
qb: selectQb,

Loading…
Cancel
Save