Skip to content

Commit 8455c97

Browse files
flovilmartRafael Santos
authored andcommitted
Fix null relation problem (parse-community#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 572684f commit 8455c97

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

spec/ParseUser.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,5 +2508,22 @@ describe('Parse.User testing', () => {
25082508
})
25092509
});
25102510
});
2511-
})
2511+
});
2512+
2513+
it_exclude_dbs(['postgres'])('should not fail querying non existing relations', done => {
2514+
let user = new Parse.User();
2515+
user.set({
2516+
username: 'hello',
2517+
password: 'world'
2518+
})
2519+
user.signUp().then(() => {
2520+
return Parse.User.current().relation('relation').query().find();
2521+
}).then((res) => {
2522+
expect(res.length).toBe(0);
2523+
done();
2524+
}).catch((err) => {
2525+
fail(JSON.stringify(err));
2526+
done();
2527+
});
2528+
});
25122529
});

src/Controllers/DatabaseController.js

Lines changed: 2 additions & 2 deletions
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)