Restores ability to include non pointer keys (#2263)
- Matches the behaviour on parse.com - fixes #2262
This commit is contained in:
@@ -2312,18 +2312,28 @@ describe('Parse.Query testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('include on the wrong key type', (done) => {
|
it_exclude_dbs(['postgres'])('supports include on the wrong key type (#2262)', function(done) {
|
||||||
var obj = new Parse.Object('TestObject');
|
let childObject = new Parse.Object('TestChildObject');
|
||||||
obj.set('foo', 'bar');
|
childObject.set('hello', 'world');
|
||||||
obj.save().then(() => {
|
childObject.save().then(() => {
|
||||||
var query = new Parse.Query('TestObject');
|
let obj = new Parse.Object('TestObject');
|
||||||
query.include('foo');
|
obj.set('foo', 'bar');
|
||||||
return query.find();
|
obj.set('child', childObject);
|
||||||
}).then((results) => {
|
return obj.save();
|
||||||
console.log('results:', results);
|
}).then(() => {
|
||||||
fail('Should have failed to query.');
|
let q = new Parse.Query('TestObject');
|
||||||
|
q.include('child');
|
||||||
|
q.include('child.parent');
|
||||||
|
q.include('createdAt');
|
||||||
|
q.include('createdAt.createdAt');
|
||||||
|
return q.find();
|
||||||
|
}).then((objs) => {
|
||||||
|
expect(objs.length).toBe(1);
|
||||||
|
expect(objs[0].get('child').get('hello')).toEqual('world');
|
||||||
|
expect(objs[0].createdAt instanceof Date).toBe(true);
|
||||||
done();
|
done();
|
||||||
}, (error) => {
|
}, (err) => {
|
||||||
|
fail('should not fail');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -527,14 +527,14 @@ function findPointers(object, path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof object !== 'object') {
|
if (typeof object !== 'object') {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'can only include pointer fields');
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.length == 0) {
|
if (path.length == 0) {
|
||||||
if (object.__type == 'Pointer') {
|
if (object.__type == 'Pointer') {
|
||||||
return [object];
|
return [object];
|
||||||
}
|
}
|
||||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'can only include pointer fields');
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var subobject = object[path[0]];
|
var subobject = object[path[0]];
|
||||||
|
|||||||
Reference in New Issue
Block a user