fix: combined and query with relational query condition returns incorrect results (#7593)
This commit is contained in:
@@ -3524,4 +3524,23 @@ describe('sendEmail', () => {
|
|||||||
'Failed to send email because no mail adapter is configured for Parse Server.'
|
'Failed to send email because no mail adapter is configured for Parse Server.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have object found with nested relational data query', async () => {
|
||||||
|
const obj1 = Parse.Object.extend('TestObject');
|
||||||
|
const obj2 = Parse.Object.extend('TestObject2');
|
||||||
|
let item2 = new obj2();
|
||||||
|
item2 = await item2.save();
|
||||||
|
let item1 = new obj1();
|
||||||
|
const relation = item1.relation('rel');
|
||||||
|
relation.add(item2);
|
||||||
|
item1 = await item1.save();
|
||||||
|
Parse.Cloud.beforeFind('TestObject', req => {
|
||||||
|
const additionalQ = new Parse.Query('TestObject');
|
||||||
|
additionalQ.equalTo('rel', item2);
|
||||||
|
return Parse.Query.and(req.query, additionalQ);
|
||||||
|
});
|
||||||
|
const q = new Parse.Query('TestObject');
|
||||||
|
const res = await q.first();
|
||||||
|
expect(res.id).toEqual(item1.id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -971,6 +971,18 @@ class DatabaseController {
|
|||||||
return Promise.resolve(query);
|
return Promise.resolve(query);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (query['$and']) {
|
||||||
|
const ors = query['$and'];
|
||||||
|
return Promise.all(
|
||||||
|
ors.map((aQuery, index) => {
|
||||||
|
return this.reduceInRelation(className, aQuery, schema).then(aQuery => {
|
||||||
|
query['$and'][index] = aQuery;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
).then(() => {
|
||||||
|
return Promise.resolve(query);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const promises = Object.keys(query).map(key => {
|
const promises = Object.keys(query).map(key => {
|
||||||
const t = schema.getExpectedType(className, key);
|
const t = schema.getExpectedType(className, key);
|
||||||
@@ -1049,7 +1061,13 @@ class DatabaseController {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (query['$and']) {
|
||||||
|
return Promise.all(
|
||||||
|
query['$and'].map(aQuery => {
|
||||||
|
return this.reduceRelationKeys(className, aQuery, queryOptions);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
var relatedTo = query['$relatedTo'];
|
var relatedTo = query['$relatedTo'];
|
||||||
if (relatedTo) {
|
if (relatedTo) {
|
||||||
return this.relatedIds(
|
return this.relatedIds(
|
||||||
|
|||||||
Reference in New Issue
Block a user