Skip to content

Commit

Permalink
fix: liveQuery with containedIn not working when object field is an…
Browse files Browse the repository at this point in the history
… array (#8128)
  • Loading branch information
stewones authored Sep 17, 2022
1 parent 4a45cc4 commit 1d9605b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spec/QueryTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,29 @@ describe('matchesQuery', function () {
expect(matchesQuery(message, q)).toBe(false);
});

it('should support containedIn with array of pointers', () => {
const message = {
id: new Id('Message', 'O2'),
profiles: [pointer('Profile', 'yeahaw'), pointer('Profile', 'yes')],
};

let q = new Parse.Query('Message');
q.containedIn('profiles', [
Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }),
Parse.Object.fromJSON({ className: 'Profile', objectId: 'yes' }),
]);

expect(matchesQuery(message, q)).toBe(true);

q = new Parse.Query('Message');
q.containedIn('profiles', [
Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }),
Parse.Object.fromJSON({ className: 'Profile', objectId: 'nope' }),
]);

expect(matchesQuery(message, q)).toBe(false);
});

it('should support notContainedIn with pointers', () => {
let message = {
id: new Id('Message', 'O1'),
Expand Down
10 changes: 10 additions & 0 deletions src/LiveQuery/QueryTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,18 @@ function contains(haystack: Array, needle: any): boolean {
return true;
}
}

return false;
}

if (Array.isArray(needle)) {
for (const need of needle) {
if (contains(haystack, need)) {
return true;
}
}
}

return haystack.indexOf(needle) > -1;
}
/**
Expand Down

0 comments on commit 1d9605b

Please sign in to comment.