fixing equals on array columns in live query (#3089)
This commit is contained in:
committed by
Florent Vilmart
parent
d800ff85e2
commit
8f1c1f419b
@@ -226,6 +226,23 @@ describe('matchesQuery', function() {
|
|||||||
|
|
||||||
img.owner.objectId = 'U3';
|
img.owner.objectId = 'U3';
|
||||||
expect(matchesQuery(img, q)).toBe(false);
|
expect(matchesQuery(img, q)).toBe(false);
|
||||||
|
|
||||||
|
// pointers in arrays
|
||||||
|
q = new Parse.Query('Image');
|
||||||
|
q.equalTo('owners', u);
|
||||||
|
|
||||||
|
img = {
|
||||||
|
className: 'Image',
|
||||||
|
objectId: 'I1',
|
||||||
|
owners: [{
|
||||||
|
className: '_User',
|
||||||
|
objectId: 'U2'
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
expect(matchesQuery(img, q)).toBe(true);
|
||||||
|
|
||||||
|
img.owners[0].objectId = 'U3';
|
||||||
|
expect(matchesQuery(img, q)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('matches on inequalities', function() {
|
it('matches on inequalities', function() {
|
||||||
|
|||||||
@@ -112,6 +112,19 @@ function matchesQuery(object: any, query: any): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function equalObjectsGeneric(obj, compareTo, eqlFn) {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
for (var i = 0; i < obj.length; i++) {
|
||||||
|
if (eqlFn(obj[i], compareTo)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return eqlFn(obj, compareTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether an object matches a single key's constraints
|
* Determines whether an object matches a single key's constraints
|
||||||
@@ -143,22 +156,16 @@ function matchesKeyConstraints(object, key, constraints) {
|
|||||||
var compareTo;
|
var compareTo;
|
||||||
if (constraints.__type) {
|
if (constraints.__type) {
|
||||||
if (constraints.__type === 'Pointer') {
|
if (constraints.__type === 'Pointer') {
|
||||||
return (
|
return equalObjectsGeneric(object[key], constraints, function(obj, ptr) {
|
||||||
typeof object[key] !== 'undefined' &&
|
return (
|
||||||
constraints.className === object[key].className &&
|
typeof obj !== 'undefined' &&
|
||||||
constraints.objectId === object[key].objectId
|
ptr.className === obj.className &&
|
||||||
);
|
ptr.objectId === obj.objectId
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
compareTo = Parse._decode(key, constraints);
|
|
||||||
if (Array.isArray(object[key])) {
|
return equalObjectsGeneric(object[key], Parse._decode(key, constraints), equalObjects);
|
||||||
for (i = 0; i < object[key].length; i++) {
|
|
||||||
if (equalObjects(object[key][i], compareTo)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return equalObjects(object[key], compareTo);
|
|
||||||
}
|
}
|
||||||
// More complex cases
|
// More complex cases
|
||||||
for (var condition in constraints) {
|
for (var condition in constraints) {
|
||||||
|
|||||||
Reference in New Issue
Block a user