Skip to content

Commit 1d9605b

Browse files
authored
fix: liveQuery with containedIn not working when object field is an array (#8128)
1 parent 4a45cc4 commit 1d9605b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

spec/QueryTools.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,29 @@ describe('matchesQuery', function () {
583583
expect(matchesQuery(message, q)).toBe(false);
584584
});
585585

586+
it('should support containedIn with array of pointers', () => {
587+
const message = {
588+
id: new Id('Message', 'O2'),
589+
profiles: [pointer('Profile', 'yeahaw'), pointer('Profile', 'yes')],
590+
};
591+
592+
let q = new Parse.Query('Message');
593+
q.containedIn('profiles', [
594+
Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }),
595+
Parse.Object.fromJSON({ className: 'Profile', objectId: 'yes' }),
596+
]);
597+
598+
expect(matchesQuery(message, q)).toBe(true);
599+
600+
q = new Parse.Query('Message');
601+
q.containedIn('profiles', [
602+
Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }),
603+
Parse.Object.fromJSON({ className: 'Profile', objectId: 'nope' }),
604+
]);
605+
606+
expect(matchesQuery(message, q)).toBe(false);
607+
});
608+
586609
it('should support notContainedIn with pointers', () => {
587610
let message = {
588611
id: new Id('Message', 'O1'),

src/LiveQuery/QueryTools.js

+10
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,18 @@ function contains(haystack: Array, needle: any): boolean {
103103
return true;
104104
}
105105
}
106+
106107
return false;
107108
}
109+
110+
if (Array.isArray(needle)) {
111+
for (const need of needle) {
112+
if (contains(haystack, need)) {
113+
return true;
114+
}
115+
}
116+
}
117+
108118
return haystack.indexOf(needle) > -1;
109119
}
110120
/**

0 commit comments

Comments
 (0)