mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: empty operator with association field (#4189)
* test: empty operator with association field * fix: test * fix: test
This commit is contained in:
parent
def7530d14
commit
69baf99b66
@ -7,7 +7,7 @@ describe('empty operator', () => {
|
||||
let db: Database;
|
||||
|
||||
let User: Collection;
|
||||
|
||||
let Profile: Collection;
|
||||
afterEach(async () => {
|
||||
await db.close();
|
||||
});
|
||||
@ -16,7 +16,23 @@ describe('empty operator', () => {
|
||||
db = mockDatabase({});
|
||||
User = db.collection({
|
||||
name: 'users',
|
||||
fields: [{ type: 'string', name: 'name' }],
|
||||
fields: [
|
||||
{ type: 'string', name: 'name' },
|
||||
{
|
||||
type: 'hasOne',
|
||||
name: 'profile',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
Profile = db.collection({
|
||||
name: 'profiles',
|
||||
fields: [
|
||||
{
|
||||
type: 'string',
|
||||
name: 'address',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await db.sync({
|
||||
@ -74,4 +90,56 @@ describe('empty operator', () => {
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
});
|
||||
|
||||
test('string not empty', async () => {
|
||||
const u1 = await User.repository.create({
|
||||
values: {
|
||||
name: 'u1',
|
||||
},
|
||||
});
|
||||
|
||||
const u2 = await User.repository.create({
|
||||
values: {
|
||||
name: '',
|
||||
},
|
||||
});
|
||||
|
||||
const result = await User.repository.find({
|
||||
filter: {
|
||||
'name.$notEmpty': true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].get('id')).toEqual(u1.get('id'));
|
||||
});
|
||||
|
||||
test('string not empty with association', async () => {
|
||||
const u1 = await User.repository.create({
|
||||
values: {
|
||||
name: 'u1',
|
||||
profile: {
|
||||
address: 'a1',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const u2 = await User.repository.create({
|
||||
values: {
|
||||
name: 'u2',
|
||||
profile: {
|
||||
address: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await User.repository.find({
|
||||
filter: {
|
||||
'profile.address.$notEmpty': true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].get('id')).toEqual(u1.get('id'));
|
||||
});
|
||||
});
|
||||
|
@ -18,11 +18,15 @@ const findFilterFieldType = (ctx) => {
|
||||
const associationPath = path;
|
||||
|
||||
for (const association of associationPath) {
|
||||
if (lodash.isNumber(parseInt(association)) || association.startsWith('$')) {
|
||||
if (lodash.isFinite(parseInt(association)) || association.startsWith('$')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
model = model.associations[association].target;
|
||||
const modelAssociation = model.associations[association];
|
||||
if (!modelAssociation) {
|
||||
break;
|
||||
}
|
||||
model = modelAssociation.target;
|
||||
}
|
||||
|
||||
const collection = db.modelCollection.get(model);
|
||||
|
@ -21,8 +21,8 @@ describe('view collection', () => {
|
||||
|
||||
db = app.db;
|
||||
|
||||
collectionRepository = app.db.getCollection('collections').repository;
|
||||
fieldsRepository = app.db.getCollection('fields').repository;
|
||||
collectionRepository = app.db.getRepository('collections');
|
||||
fieldsRepository = app.db.getRepository('fields');
|
||||
|
||||
agent = app.agent();
|
||||
testViewName = `view_${uid(6)}`;
|
||||
@ -283,7 +283,7 @@ SELECT * FROM numbers;
|
||||
});
|
||||
|
||||
it('should list collections fields with source interface', async () => {
|
||||
await app.db.getCollection('collections').repository.create({
|
||||
await app.db.getRepository('collections').create({
|
||||
values: {
|
||||
name: 'users',
|
||||
fields: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user