Browse Source

fix: group by related fixes

pull/7304/head
Pranav C 11 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 { import {
AuditOperationSubTypes, AuditOperationSubTypes,
AuditOperationTypes, AuditOperationTypes,
isCreatedTimeOrUpdatedTimeCol,
isLinksOrLTAR, isLinksOrLTAR,
isSystemColumn, isSystemColumn,
isVirtualCol, isVirtualCol,
@ -102,7 +103,9 @@ function checkColumnRequired(
} }
export async function getColumnName(column: Column<any>, columns?: Column[]) { 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 })); columns = columns || (await Column.list({ fk_model_id: column.fk_model_id }));
switch (column.uidt) { switch (column.uidt) {
case UITypes.CreatedTime: { case UITypes.CreatedTime: {
const createdTimeSystemCol = columns.find( const createdTimeSystemCol = columns.find(
@ -664,10 +667,13 @@ class BaseModelSqlv2 {
} }
break; break;
default: default:
selectors.push( {
this.dbDriver.raw('?? as ??', [column.column_name, column.id]), const columnName = await getColumnName(column, cols);
); selectors.push(
groupBySelectors.push(sanitize(column.id)); this.dbDriver.raw('?? as ??', [columnName, column.id]),
);
groupBySelectors.push(sanitize(column.id));
}
break; break;
} }
}), }),
@ -872,10 +878,13 @@ class BaseModelSqlv2 {
} }
break; break;
default: default:
selectors.push( {
this.dbDriver.raw('?? as ??', [column.column_name, column.id]), const columnName = await getColumnName(column, cols);
); selectors.push(
groupBySelectors.push(sanitize(column.id)); this.dbDriver.raw('?? as ??', [columnName, column.id]),
);
groupBySelectors.push(sanitize(column.id));
}
break; 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 LookupColumn from '~/models/LookupColumn';
import type RollupColumn from '~/models/RollupColumn'; import type RollupColumn from '~/models/RollupColumn';
import type FormulaColumn from '~/models/FormulaColumn'; import type FormulaColumn from '~/models/FormulaColumn';
import { getColumnName } from '~/db/BaseModelSqlv2';
import { type BarcodeColumn, BaseUser, type QrCodeColumn } from '~/models'; import { type BarcodeColumn, BaseUser, type QrCodeColumn } from '~/models';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2'; import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2';
@ -544,6 +545,9 @@ const parseConditionV2 = async (
); );
const _val = customWhereClause ? customWhereClause : filter.value; const _val = customWhereClause ? customWhereClause : filter.value;
// get column name for CreateTime, LastModifiedTime
column.column_name = await getColumnName(column);
return (qb: Knex.QueryBuilder) => { return (qb: Knex.QueryBuilder) => {
let [field, val] = [_field, _val]; let [field, val] = [_field, _val];
@ -678,7 +682,7 @@ const parseConditionV2 = async (
].includes(column.uidt) ].includes(column.uidt)
) { ) {
if (qb.client.config.client === 'pg') { if (qb.client.config.client === 'pg') {
qb = qb.where(knex.raw('??::date = ?', [field, val])); qb = qb.where(knex.raw('??::timestamp = ?', [field, val]));
} else { } else {
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val])); 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; break;
case UITypes.DateTime: case UITypes.DateTime:
case UITypes.LastModifiedTime:
case UITypes.CreatedTime:
{ {
await baseModelSqlv2.selectObject({ await baseModelSqlv2.selectObject({
qb: selectQb, qb: selectQb,

Loading…
Cancel
Save