Open
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
Hi !
I have a beforeFind
trigger that add a few restrictions on a child type, when executing parent.query().find()
the server throw a Invalid key "$relatedTo"
Steps to reproduce
I have a Parent
with a relation
to a Child
Then:
// /cloud/index.js
Parse.Cloud.beforeFind("Child", (req) => {
const a = new Parse.Query("Child")
const b = new Parse.Query("Child")
a.equalTo('field', 'abcd')
b.doesNotExist('field')
return Parse.Query.and(req.query, Parse.Query.or(a, b) )
})
On the client
// client
const parent = new Parent()
await parent.relation('childs').query().find()
Actual Outcome
Error in mounted hook (Promise/async): "ParseError: 105 Invalid key name: $relatedTo"
Expected Outcome
An happy relation! 👪
Failing Test Case / Pull Request
It seems that reduceRelationKeys
only checks for a Top level $or
, and in my case, the top level operator is $and
This seems like it 'fixes' the issue :
reduceRelationKeys(className, query, queryOptions) {
// if (query['$or']) {
// return Promise.all(query['$or'].map(aQuery => {
// return this.reduceRelationKeys(className, aQuery, queryOptions);
// }));
// }
for(const op of ['$or', '$and' , '$not']) {
if (query[op]) {
return Promise.all(query[op].map(aQuery => {
return this.reduceRelationKeys(className, aQuery, queryOptions);
}));
}
}
// ....
- 🤩 I submitted a PR with a fix and a test case.
- 🧐 I submitted a PR with a failing test case.
Environment
Server
- Parse Server version:
4.5.0
- Operating system:
windows
- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc):
local
Database
- System (MongoDB or Postgres):
mongo
- Database version:
4.4?
- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
local
Client
- SDK (iOS, Android, JavaScript, PHP, Unity, etc):
js
- SDK version:
3.1.0
Logs
Metadata
Metadata
Assignees
Labels
No labels