Skip to content

Allows dot-notation to match against a complex structure when using matchesKeyInQuery #4308

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

Closed
wants to merge 2 commits into from
Closed
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
42 changes: 42 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}))
})
});
});
2 changes: 1 addition & 1 deletion src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change this for transformSelect we should also change the similar code in transformDontSelect. Additionally another test should then be added to account for doesNotMatchKeyInQuery having this modified behavior as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, totally missed that. I'll give it a go soon (tm)

}
delete selectObject['$select'];
if (Array.isArray(selectObject['$in'])) {
Expand Down