Reputation: 4150
i'm trying to manage friendship using parse.com but i have some trouble because i usually use sql db. In parse i've a tab "user" and i'm using a column type relation that point to the same tab user. Is it correct?
Now i'm trying to add friend but appear this error:post 400 (Bad Request);
var Models = {};
Models.utenti = new Usercollection();
Models.utenti.fetch({
success: function(object) {
console.log(object);
},
error: function(amici, error) {
}
});
var amico=Models.utenti.get("xj3QLLYy07");
var user = Parse.User.current();
var relation = user.relation("amici");
relation.add(amico);
user.save();
Upvotes: 0
Views: 264
Reputation: 9295
It is ok to make relation to the same table (User relation to User). If you want to add new user to relation of other user you can do it this way:
var curUser = Parse.User.current();
var userQuery = new Parse.Query(Parse.User);
userQuery.equalTo("objectId", "userId_you_want_to_add"); //xj3QLLYy07
//find the user you want to add
userQuery.first().then
(
function(userToAdd)
{
var relation = curUser.relation("amici");
//add user to relation
relation.add(userToAdd);
curUser.save();
},
function(error)
{
console.log("error: " + error.message);
}
);
Hope this would help you.
Upvotes: 1