parse.com - Create new object with relation in Parse with React Native -
there seems no documentation on how create new parse object relation parse-reactnative using parsereact.mutation.create
. resorted this:
function createrow(relatedobject, data) { parsereact.mutation.create('objectclass', data) .dispatch() .then(function(newrow) { parsereact.mutation.addrelation(newrow, 'relationcolumn', relatedobject) }); }
which creating new objectclass
parse object, column relationcolumn
doesn't display relation given relatedobject
.
any idea on how can done, preferably in 1 query parsereact.mutation.create
?
so code working parsereact.mutation.addrelation
, here is:
parsereact.mutation.addrelation({ "classname": newrow.classname, "objectid": newrow.id.objectid}, 'groceryrequestrelation',[{ "__type":"pointer", "classname":"classthepointerpointingto", "objectid":"objectidofclassthepointerispointingto" }]).dispatch()
@naoisegolden didn't put .dispatch()
@ end of addrelation
might issue.
another thing took me forever figure out was using wrong objectid
within addrelation
, should be using objectid
of class the pointer pointing to, using objectid
of class relation
belongs to...
if still doesn't work you, try rest way this:
var data = { "groceryrequestrelation":{"__op":"addrelation", "objects": [{ "__type":"pointer", "classname":"classthepointerispointingto", "objectid":"objectidofclassthepointerispointingto" } ] } }; var url = "https://api.parse.com"; url += "/1/classes/classname/objectid"; fetch(url, { method: 'put', headers: { 'accept': 'application/json', 'x-parse-application-id': parse_app_id, 'x-parse-rest-api-key': parse_rest_key, 'content-type': 'application/json' }, body: json.stringify(data) }) .then((response) => { console.log("inside add relation rest") console.log(response); return response.json(); }) .then((responsetext) => { console.log(responsetext); }) .catch((error) => { console.warn(error); }) .done();
Comments
Post a Comment