fix: operator query value (#216)

* fix: operator query value

* fix: operator query value
This commit is contained in:
ChengLei Shao 2022-03-02 22:01:32 +08:00 committed by GitHub
parent 78ada4d6ec
commit b354313c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -39,4 +39,24 @@ describe('string operator', () => {
expect(u1Res.get('id')).toEqual(u1.get('id'));
});
it('should query with and ', async () => {
const u1 = await db.getRepository('users').create({
values: {
name: 'names of u1',
},
});
const u1Res = await db.getRepository('users').findOne({
filter: {
$and: [
{
'name.$includes': 'u1',
},
],
},
});
expect(u1Res.get('id')).toEqual(u1.get('id'));
});
});

View File

@ -1,4 +1,4 @@
import { flatten } from 'flat';
import { flatten, unflatten } from 'flat';
import { default as lodash, default as _ } from 'lodash';
import { ModelCtor } from 'sequelize';
import { Collection } from './collection';
@ -121,7 +121,7 @@ export default class FilterParser {
} else if (typeof opKey === 'function') {
skipPrefix = origins.join('.');
value = opKey(originalFiler[skipPrefix], {
value = opKey(lodash.get(unflatten(originalFiler), skipPrefix), {
db: this.database,
path: skipPrefix,
fieldName: skipPrefix.replace(`.${firstKey}`, ''),