From c28092c72f5bb4aca6f86f1208ea9e0f5df517bb Mon Sep 17 00:00:00 2001 From: Henrik Malmberg Date: Tue, 31 Oct 2017 11:34:25 +0100 Subject: [PATCH 1/4] 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 8ddda22cba..b1ffb3a300 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -337,7 +337,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 ac0a981d746710cfcc5360d7f927fa122cb804a3 Mon Sep 17 00:00:00 2001 From: Henrik Malmberg Date: Wed, 1 Nov 2017 11:17:10 +0100 Subject: [PATCH 2/4] 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 20bc916599..447b45a16c 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -3206,4 +3206,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(); + } + })) + }) + }); }); From d60dc3295fdd1a37094fbfa4c35d9708546f70a5 Mon Sep 17 00:00:00 2001 From: Arthur Cinader <700572+acinader@users.noreply.github.com> Date: Tue, 28 Nov 2017 17:02:14 -0800 Subject: [PATCH 3/4] Add doesNotMatchKeyInQuery case... --- spec/ParseQuery.spec.js | 43 +++++++++++++++++++++++++++++++++++++++++ src/RestQuery.js | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 447b45a16c..08f22d1683 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -3248,4 +3248,47 @@ describe('Parse.Query testing', () => { })) }) }); + + 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.doesNotMatchKeyInQuery('objectId', 'belongsTo.objectId', rolesOfTypeX); + + groupsWithRoleX.find(expectSuccess({ + success: function(results) { + equal(results.length, 1); + equal(results[0].get('name'), group2.get('name')); + done(); + } + })) + }) + }); + }); diff --git a/src/RestQuery.js b/src/RestQuery.js index b1ffb3a300..0af910522b 100644 --- a/src/RestQuery.js +++ b/src/RestQuery.js @@ -392,7 +392,7 @@ RestQuery.prototype.replaceSelect = function() { const transformDontSelect = (dontSelectObject, key, objects) => { var values = []; for (var result of objects) { - values.push(result[key]); + values.push(key.split('.').reduce((o,i)=>o[i], result)); } delete dontSelectObject['$dontSelect']; if (Array.isArray(dontSelectObject['$nin'])) { From ce5bc4cd7477934cdfa1e7c3fcc38fba47803453 Mon Sep 17 00:00:00 2001 From: Arthur Cinader <700572+acinader@users.noreply.github.com> Date: Wed, 29 Nov 2017 10:07:08 -0800 Subject: [PATCH 4/4] Fix test name to match what's tested --- spec/ParseQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseQuery.spec.js b/spec/ParseQuery.spec.js index 08f22d1683..000fbe6214 100644 --- a/spec/ParseQuery.spec.js +++ b/spec/ParseQuery.spec.js @@ -3249,7 +3249,7 @@ describe('Parse.Query testing', () => { }) }); - it('should match complex structure with dot notation when using matchesKeyInQuery', function(done) { + it('should match complex structure with dot notation when using doesNotMatchKeyInQuery', function(done) { const group1 = new Parse.Object('Group', { name: 'Group #1' });