Search code examples
javascriptparsingparse-platform

Parse Cloud Code: "Cannot call method '_toPointer' of null" when calling .query() on a relation


This is something that I struggled with, and couldn't find a quick answer for. Ultimately, I realized that I wasn't reviewing the Parse documentation properly.

Problem

If you're reading this question, perhaps you're getting the following error in your Cloud Code error log

Result: TypeError: Cannot call method '_toPointer' of null

when you try to call the .query() method of a Parse.Relation.


Solution

  • Solution

    Consider that you may be retrieving the relation incorrectly, in the first place. I spent quite a while struggling to understand why, if I called the .get('RELATION_KEY') method of a Parse.Object, I kept getting this error.

    I should have been calling .relation('RELATION_KEY') instead. I know this is was in the Parse.Object documentation, but I saw "get" and stopped reading. My mistake.

    Hope it helps.