Skip to content

Commit 025482e

Browse files
flovilmartdrew-gross
authored andcommitted
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
1 parent f310e66 commit 025482e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: spec/ParseUser.spec.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -2595,5 +2595,22 @@ describe('Parse.User testing', () => {
25952595
})
25962596
});
25972597
});
2598-
})
2598+
});
2599+
2600+
it_exclude_dbs(['postgres'])('should not fail querying non existing relations', done => {
2601+
let user = new Parse.User();
2602+
user.set({
2603+
username: 'hello',
2604+
password: 'world'
2605+
})
2606+
user.signUp().then(() => {
2607+
return Parse.User.current().relation('relation').query().find();
2608+
}).then((res) => {
2609+
expect(res.length).toBe(0);
2610+
done();
2611+
}).catch((err) => {
2612+
fail(JSON.stringify(err));
2613+
done();
2614+
});
2615+
});
25992616
});

Diff for: src/Controllers/DatabaseController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A database adapter that works with data exported from the hosted
1+
// A database adapter that works with data exported from the hosted
22
// Parse database.
33

44
import intersect from 'intersect';
@@ -121,7 +121,7 @@ DatabaseController.prototype.loadSchema = function() {
121121
DatabaseController.prototype.redirectClassNameForKey = function(className, key) {
122122
return this.loadSchema().then((schema) => {
123123
var t = schema.getExpectedType(className, key);
124-
if (t.type == 'Relation') {
124+
if (t && t.type == 'Relation') {
125125
return t.targetClass;
126126
} else {
127127
return className;

0 commit comments

Comments
 (0)