From 43641125e718b0b3e80e875cb8d57b18e637651a Mon Sep 17 00:00:00 2001 From: Henrik Malmberg Date: Tue, 31 Oct 2017 11:34:25 +0100 Subject: [PATCH 1/2] Allows to use dot-notation to match against a complex structure when using matchesKeyInQuery --- src/RestQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RestQuery.js b/src/RestQuery.js index 7126814152..ee352f70d4 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -335,7 +335,7 @@ RestQuery.prototype.replaceNotInQuery = function() { const transformSelect = (selectObject, key ,objects) => { var values = []; for (var result of objects) { - values.push(result[key]); + values.push(key.split('.').reduce((o,i)=>o[i], result)); } delete selectObject['$select']; if (Array.isArray(selectObject['$in'])) { From 038e759be55f5cbb7fdf54f6824855d51e064e50 Mon Sep 17 00:00:00 2001 From: Henrik Malmberg Date: Wed, 1 Nov 2017 11:17:10 +0100 Subject: [PATCH 2/2] added test for dot-notation in matchesKeyInQuery --- spec/ParseQuery.spec.js | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 15884a1cd1..dc494718cb 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -3181,4 +3181,46 @@ describe('Parse.Query testing', () => { .then(() => q.find({ useMasterKey: true })) .then(done.fail, done); }); + + it('should match complex structure with dot notation when using matchesKeyInQuery', function(done) { + const group1 = new Parse.Object('Group', { + name: 'Group #1' + }); + + const group2 = new Parse.Object('Group', { + name: 'Group #2' + }); + + Parse.Object.saveAll([group1, group2]) + .then(() => { + const role1 = new Parse.Object('Role', { + name: 'Role #1', + type: 'x', + belongsTo: group1 + }); + + const role2 = new Parse.Object('Role', { + name: 'Role #2', + type: 'y', + belongsTo: group1 + }); + + return Parse.Object.saveAll([role1, role2]); + }) + .then(() => { + const rolesOfTypeX = new Parse.Query('Role'); + rolesOfTypeX.equalTo('type', 'x'); + + const groupsWithRoleX = new Parse.Query('Group'); + groupsWithRoleX.matchesKeyInQuery('objectId', 'belongsTo.objectId', rolesOfTypeX); + + groupsWithRoleX.find(expectSuccess({ + success: function(results) { + equal(results.length, 1); + equal(results[0].get('name'), group1.get('name')); + done(); + } + })) + }) + }); });