Skip to content

[NEW] Allows dot-notation to match against a complex structure when using matchesKeyInQuery #4399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3206,4 +3206,89 @@ 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();
}
}))
})
});

it('should match complex structure with dot notation when using doesNotMatchKeyInQuery', 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();
}
}))
})
});

});
4 changes: 2 additions & 2 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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'])) {
Expand Down