feat: the $anyof and $noneOf operators should support non-array values (#3244)
* fix: the $anyof and $noneOf operators should support non-array values * chore: add lodash dependency * test: add unit test * test: add unit test
This commit is contained in:
parent
5e89a02044
commit
d570a2c704
@ -23,7 +23,8 @@
|
||||
"qs": "^6.11.2",
|
||||
"semver": "^7.3.7",
|
||||
"sequelize": "^6.26.0",
|
||||
"umzug": "^3.1.1"
|
||||
"umzug": "^3.1.1",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^7.2.0",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { mockDatabase } from '../index';
|
||||
import Database from '../../database';
|
||||
import { mockDatabase } from '../index';
|
||||
|
||||
describe('array field operator', function () {
|
||||
let db: Database;
|
||||
@ -195,6 +195,18 @@ describe('array field operator', function () {
|
||||
expect(filter3[0].get('name')).toEqual(t2.get('name'));
|
||||
});
|
||||
|
||||
// fix https://nocobase.height.app/T-2803
|
||||
test('$anyOf with string', async () => {
|
||||
const filter3 = await Test.repository.find({
|
||||
filter: {
|
||||
'selected.$anyOf': 'aa',
|
||||
},
|
||||
});
|
||||
|
||||
expect(filter3.length).toEqual(1);
|
||||
expect(filter3[0].get('name')).toEqual(t2.get('name'));
|
||||
});
|
||||
|
||||
test('$anyOf with multiple items', async () => {
|
||||
const filter3 = await Test.repository.find({
|
||||
filter: {
|
||||
@ -216,6 +228,18 @@ describe('array field operator', function () {
|
||||
expect(filter[0].get('name')).toEqual(t1.get('name'));
|
||||
});
|
||||
|
||||
// fix https://nocobase.height.app/T-2803
|
||||
test('$noneOf with string', async () => {
|
||||
const filter = await Test.repository.find({
|
||||
filter: {
|
||||
'selected.$noneOf': 'aa',
|
||||
},
|
||||
});
|
||||
|
||||
expect(filter.length).toEqual(1);
|
||||
expect(filter[0].get('name')).toEqual(t1.get('name'));
|
||||
});
|
||||
|
||||
test('$noneOf with null', async () => {
|
||||
const t3 = await Test.repository.create({
|
||||
values: {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { Op, Sequelize } from 'sequelize';
|
||||
import { isMySQL, isPg } from './utils';
|
||||
|
||||
@ -87,6 +88,7 @@ export default {
|
||||
|
||||
$anyOf(value, ctx) {
|
||||
const fieldName = getFieldName(ctx);
|
||||
value = _.castArray(value);
|
||||
|
||||
if (isPg(ctx)) {
|
||||
const name = ctx.fullName === fieldName ? `"${ctx.model.name}"."${fieldName}"` : `"${fieldName}"`;
|
||||
@ -111,6 +113,7 @@ export default {
|
||||
|
||||
$noneOf(value, ctx) {
|
||||
let where;
|
||||
value = _.castArray(value);
|
||||
|
||||
if (isPg(ctx)) {
|
||||
const fieldName = getFieldName(ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user