Create a new object with a relationship in Parse with React Native

There seems to be no documentation on how to create a new Parse object with a Parse-ReactNative relationship using ParseReact.Mutation.Create . I turned to this:

 function createRow(relatedObject, data) { ParseReact.Mutation.Create('objectClass', data) .dispatch() .then(function(newRow) { ParseReact.Mutation.AddRelation(newRow, 'relationColumn', relatedObject) }); } 

Which creates a new objectClass Parse Object, but the relationColumn column does not display the relationship with this relatedObject .

Any idea on how to do this, preferably in a single request with ParseReact.Mutation.Create ?

+6
source share
1 answer

so my code works with ParseReact.Mutation.AddRelation , here it is:

 ParseReact.Mutation.AddRelation({ "className": newRow.className, "objectId": newRow.id.objectId}, 'groceryRequestRelation',[{ "__type":"Pointer", "className":"ClassThePointerPointingTo", "objectId":"ObjectIdOfClassThePointerIsPointingTo" }]).dispatch() 

@naoisegolden you did not put .dispatch() at the end of AddRelation so this could be a problem.

One more thing that required me to find out forever if I was the wrong objectId in my AddRelation , I should be using the objectId of the class that points to the pointer , but I used the objectId class to which the relation belongs ...

If this does not work for you, try the REST method:

 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(); 
+2
source

All Articles