Parsing, add attitude. Unable to encode link to unsaved ParseObject
I am trying to add a relation to users of a table with bars in a table pane. Bars already exist in my database, but I always get the error "Unable to encode communication with unsaved ParseObject".
ParseUser user = ParseUser.getCurrentUser();
ParseObject barParseObject = ParseObject.createWithoutData(TABLE_BAR, bar.getBarId());
ParseRelation<ParseObject> relation = user.getRelation(ApiUserMapper.FIELD_LIKES);
if (bar.isFavourite()) {
relation.add(barParseObject);
} else {
relation.remove(barParseObject);
}
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
resultCallback.processResults(bar);
} else {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Error: updateFav " + e.getMessage());
}
resultCallback.processError(e);
}
}
});
bar.getBarId () contains a valid ObjectId already stored in the database, but I also tried requesting this bar earlier with the same result.
ParseQuery<ParseObject> query = ParseQuery.getQuery(TABLE_BAR);
query.getInBackground(bar.getBarId(), new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseRelation<ParseObject> relation = user.getRelation(ApiUserMapper.FIELD_LIKES);
if (bar.isFavourite()) {
relation.add(object);
} else {
relation.remove(object);
}
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
resultCallback.processResults(bar);
} else {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Error: updateFav " + e.getMessage());
}
resultCallback.processError(e);
}
}
});
}
}
});
If I try to add the relation the other way around, it works fine. But I want the relationship to be added to the User table.
ParseObject barParseObject = ParseObject.createWithoutData(TABLE_BAR, bar.getBarId());
ParseRelation<ParseObject> relation = barParseObject.getRelation(ApiUserMapper.FIELD_LIKES);
relation.add(user);
barParseObject.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
resultCallback.processResults(bar);
} else {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Error: updateFav " + e.getMessage());
} else {
Crashlytics.log(LOG_PRIORITY, TAG, "Error: updateFav " + e.getMessage());
}
resultCallback.processError(e);
}
}
});
Any hints? Something to do with permissions? I am assuming the current user can write their own data, but I do not have any specific setting in my code.
Thank!
+3
source to share