così il mio codice sta lavorando con ParseReact.Mutation.AddRelation
, eccolo:
ParseReact.Mutation.AddRelation({
"className": newRow.className,
"objectId": newRow.id.objectId}, 'groceryRequestRelation',[{
"__type":"Pointer",
"className":"ClassThePointerPointingTo",
"objectId":"ObjectIdOfClassThePointerIsPointingTo"
}]).dispatch()
@naoisegolden non hai messo .dispatch()
alla fine del AddRelation
in modo che potrebbe essere un problema.
Un'altra cosa che mi ha preso per sempre per capire era che stavo usando il sbagliatoobjectId
nel mio AddRelation
, ho dovrei essere utilizzando il objectId
della classe che il puntatore punta a, ma stavo usando il objectId
della classe che il relation
appartiene a ...
Se questo non funziona ancora per te, prova il modo REST per farlo:
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();
fonte
2015-10-24 22:59:51
Aggiungere la spedizione() per AddRelation ha fatto il trucco per me. Grazie Kevin! – mutp
È inoltre possibile passare una matrice di oggetti come ultimo parametro in AddRelation. Per es. puoi passare un array di oggetti User se vuoi aggiungere quella relazione ad una classe. – mutp
@muttapp np, felice di aiutare! –