Search code examples
push-notificationparse-cloud-codeparse-server

Parse Server - Installation class missing user column


I am trying to send push notification to specific user using parse server. However, the Installation Class doesn't have the user column that points to which user has this installation. Hence, the query for the installation returns nothing. My question is should the installation class create the user column automatically, or should I relate them somehow? and if so, any help would be appreciated.

P.S. I'm sending the push notification using Cloud Code. So I'm using javascript.


Solution

  • The Installation class does not automatically set the User column - you have to do it manually.

    I suggest that you create and save the User, and then the success callback will have the saved User object as a parameter, and you can then set the User in your Installation document.

    Here's a quick snippet:

    var currentInstallation;
    installationModule.getInstallationById(installationId)
      .then(function (installation) {
        if (installation) {
          currentInstallation = installation;
          var user = createParseUser(newUser);
          return user.save();
        }
        else {
          // return error
        }
      })
      .then(function (user) {
        currentInstallation.set('user', user);
        return currentInstallation.save()
      }, function (error) {
        // TODO: handle error
      });