Fix null relation problem (#2319)

* Add null check for relation type map.

For relations that are not explicitly defined in the schema, we need a null check here.

* Making change to force rebuild.

* Reverting change.

* Adds test
This commit is contained in:
Florent Vilmart
2016-07-19 01:58:37 -04:00
committed by Drew
parent f310e6678e
commit 025482ea1a
2 changed files with 20 additions and 3 deletions

View File

@@ -2595,5 +2595,22 @@ describe('Parse.User testing', () => {
}) })
}); });
}); });
}) });
it_exclude_dbs(['postgres'])('should not fail querying non existing relations', done => {
let user = new Parse.User();
user.set({
username: 'hello',
password: 'world'
})
user.signUp().then(() => {
return Parse.User.current().relation('relation').query().find();
}).then((res) => {
expect(res.length).toBe(0);
done();
}).catch((err) => {
fail(JSON.stringify(err));
done();
});
});
}); });

View File

@@ -1,4 +1,4 @@
// A database adapter that works with data exported from the hosted // A database adapter that works with data exported from the hosted
// Parse database. // Parse database.
import intersect from 'intersect'; import intersect from 'intersect';
@@ -121,7 +121,7 @@ DatabaseController.prototype.loadSchema = function() {
DatabaseController.prototype.redirectClassNameForKey = function(className, key) { DatabaseController.prototype.redirectClassNameForKey = function(className, key) {
return this.loadSchema().then((schema) => { return this.loadSchema().then((schema) => {
var t = schema.getExpectedType(className, key); var t = schema.getExpectedType(className, key);
if (t.type == 'Relation') { if (t && t.type == 'Relation') {
return t.targetClass; return t.targetClass;
} else { } else {
return className; return className;