mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 16:23:30 +00:00
fix: scope key error (#5322)
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
Test on Windows / build (push) Waiting to run
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
Test on Windows / build (push) Waiting to run
* fix: scope key error * fix: group by scope key * fix: test
This commit is contained in:
parent
786e1e4f25
commit
2199969579
@ -11,7 +11,7 @@ import { Database } from '../../database';
|
||||
import { mockDatabase } from '../';
|
||||
import { SortField } from '../../fields';
|
||||
|
||||
describe('string field', () => {
|
||||
describe('sort field', () => {
|
||||
let db: Database;
|
||||
|
||||
beforeEach(async () => {
|
||||
@ -37,7 +37,7 @@ describe('string field', () => {
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
name: 'scopeKey',
|
||||
name: 'someField',
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -45,13 +45,19 @@ describe('string field', () => {
|
||||
await db.sync();
|
||||
|
||||
await Test.repository.create({
|
||||
values: {
|
||||
name: 't1',
|
||||
scopeKey: 'a',
|
||||
},
|
||||
values: [
|
||||
{
|
||||
name: 't1',
|
||||
someField: 'a',
|
||||
},
|
||||
{
|
||||
name: 't2',
|
||||
someField: 'b',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Test.setField('scopeKeySort', { type: 'sort', scopeKey: 'scopeKey' });
|
||||
Test.setField('scopeKeySort', { type: 'sort', scopeKey: 'someField' });
|
||||
await db.sync();
|
||||
});
|
||||
|
||||
|
@ -460,10 +460,6 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
||||
}
|
||||
|
||||
if (options.underscored) {
|
||||
if (lodash.get(options, 'sortable.scopeKey')) {
|
||||
options.sortable.scopeKey = snakeCase(options.sortable.scopeKey);
|
||||
}
|
||||
|
||||
if (lodash.get(options, 'indexes')) {
|
||||
// change index fields to snake case
|
||||
options.indexes = options.indexes.map((index) => {
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
import { Mutex } from 'async-mutex';
|
||||
import { isNumber } from 'lodash';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { DataTypes, Sequelize } from 'sequelize';
|
||||
import { BaseColumnFieldOptions, Field } from './field';
|
||||
|
||||
const sortFieldMutex = new Mutex();
|
||||
@ -171,10 +171,12 @@ export class SortField extends Field {
|
||||
};
|
||||
|
||||
const scopeKey = this.options.scopeKey;
|
||||
|
||||
if (scopeKey) {
|
||||
const groups = await this.collection.repository.find({
|
||||
attributes: [scopeKey],
|
||||
group: [scopeKey],
|
||||
const scopeKeyColumn = this.collection.model.rawAttributes[scopeKey].field;
|
||||
|
||||
const groups = await this.collection.model.findAll({
|
||||
attributes: [[Sequelize.fn('DISTINCT', Sequelize.col(scopeKeyColumn)), scopeKey]],
|
||||
raw: true,
|
||||
transaction,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user