Skip to content

Commit

Permalink
Fix null relation problem (parse-community#2319)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
flovilmart authored and Rafael Santos committed Mar 16, 2017
1 parent ee51538 commit cbda60c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2488,5 +2488,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();
});
});
});
4 changes: 2 additions & 2 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
@@ -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.

import intersect from 'intersect';
Expand Down Expand Up @@ -121,7 +121,7 @@ DatabaseController.prototype.loadSchema = function() {
DatabaseController.prototype.redirectClassNameForKey = function(className, key) {
return this.loadSchema().then((schema) => {
var t = schema.getExpectedType(className, key);
if (t.type == 'Relation') {
if (t && t.type == 'Relation') {
return t.targetClass;
} else {
return className;
Expand Down

0 comments on commit cbda60c

Please sign in to comment.