javascript - Adding object to PFRelation through Cloud Code -


i trying add object pfrelation in cloud code. i'm not comfortable js after few hours, i've thrown in towel.

                    var relation = user.relation("habits");                     relation.add(newhabit);                      user.save().then(function(success) {                         response.success("success!");                     }); 

i made sure user , habit valid objects isn't issue. also, since editing pfuser, using masterkey:

    parse.cloud.usemasterkey(); 

don't throw in towel yet. cause hinted @ variable name newhabit. if it's new, that's problem. objects being saved relations have have once been saved themselves. cannot new.

so...

var user = // got user somehow var newhabit = // create new habit // save it, , use promises keep code organized newhabit.save().then(function() {     // newhabit no longer new, maybe wasn't great variable name     var relation = user.relation("habits");     relation.add(newhabit);      return user.save(); }).then(function(success) {     response.success(success); }, function(error) {     // have had hint if line here     response.error(error); }); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -