From cbda60ca938f0ef0cd34704ecbf2f6cf978a0dae Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Tue, 19 Jul 2016 01:58:37 -0400 Subject: [PATCH] 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 --- spec/ParseUser.spec.js | 19 ++++++++++++++++++- src/Controllers/DatabaseController.js | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index 317138792b..4840f39602 100644 --- a/spec/ParseUser.spec.js +++ b/spec/ParseUser.spec.js @@ -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(); + }); + }); }); diff --git a/src/Controllers/DatabaseController.js b/src/Controllers/DatabaseController.js index 811f9b0a3e..09891a3c98 100644 --- a/src/Controllers/DatabaseController.js +++ b/src/Controllers/DatabaseController.js @@ -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'; @@ -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;