0

In Parse, I can create an object with a relation like:

var obj = new Something();
var relation = obj.relation('x');
relation.add(somethingElse);
obj.save();

But how do I do the same with the REST API? I find that I cannot just pass an array of pointers.

I get something like:

invalid type for key members, expected relation<_User>, but got array.

In the docs, it says I can add objects to a relation with the update API, but no mention with the create API.

1 Answer 1

1

if you want a parse property to be array of pointers to say _User, then just make sure that its property is of correct type (empty javascript array) when you create the object ...

and then use the "addUnique()" , "add()" or "remove()" methods to update the content of the array. sample below with pointers to _User in array..

var _user;
var query = new Parse.Query(Parse.Object.extend("MyClz"));
query.include("arrayPointer");
Parse.User.current().fetch().then(function (user) {
  _user = user;
  return query.get(_OID-MyClz);
}).then(function(myClz){
  myClz.addUnique("arrayPointer",_user);
  return myClz.save(); 

in Rest it looks like below:

{"myArray":{"__op":"AddRelation","objects":[{"__type":"Pointer","className":"_User","objectId":""}]}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.