Description
Issue Description
When using dot notation on a doesNotMatchKeyInQuery
query constraint, the query will error if a result from the original query does not have an object for the base queryKey that uses dot notation. The workaround is to add a exists
constraint to the query, though it seems that should be implicit if an error is going to be thrown otherwise.
Steps to reproduce
Create ClassA
and ClassB
.
Add a pointer field to ClassB
on ClassA
called classB
.
Create one instance of ClassB
and two instances of ClassA
On one instance of ClassA
, attach the pointer to the instance of ClassB
Call the following cloud code function:
Parse.Cloud.define('queryErrorTest', function(request, response) {
var queryA = new Parse.Query('ClassA');
var queryB = new Parse.Query('ClassB');
queryB.doesNotMatchKeyInQuery('objectId', 'classB.objectId', queryA);
queryB.count().then(
results => { response.success(`Found ${count} objects`); },
error => { response.error('Query Failed'); }
);
});
Expected Results
Print Found 1 objects
Actual Outcome
An error saying Cannot read property 'objectId' of undefined
Adding the line queryA.exists('classB');
solves the issue, and I get the expected outcome. The error would not occur if there were no instances of ClassA
that did not have their classB
pointer, so keep that in mind if a test case is written. If dot notation is used on the queryKey parameter of doesNotMatchKeyInQuery
, the exists
call should be implicit. Without knowing the code that is actually being run, it seems like another fix would be to add an undefined check before trying to access the nested field, but the implicit exists
call seems to me to be a more efficient solution.
I have not tested this on the other related methods, like matchesKeyInQuery
, though I imagine results would be similar. I also only tested this on the queryKey
parameter.
Environment Setup
-
Server
- parse-server version (Be specific! Don't say 'latest'.) : 2.7.4
- Operating System: Mac OS High Sierra 10.13.4 (17E202)
- Hardware: 2015 MBP
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Local
-
Database
- MongoDB version: ??
- Storage engine: ??
- Hardware: ??
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab
Logs/Trace
Cannot read property 'objectId' of undefined