Error Saving Object

I have an object, PictureModel, and am trying to update it. PictureModel has an integer field called YesVotes that I’m trying to increment. PictureModel also has a relational field UserID (maybe not the best name as I’m still learning backendless) to the System Users table.
Code used to increment (model is a PictureModel retrieved from the database):
model.setYesVotes(model.getYesVotes() + 1);Backendless.Persistence.save(model, new AsyncCallback<TModel>() {
public void handleResponse(TModel savedModel )
{
// saved
}
@Override
public void handleFault(BackendlessFault fault )
{
// error
}
});
fault returns the error: 8011 “Users can only be added as related objects by specifying their valid object ID, all other values are ignored. For creating Users please use User API.”
model.UserID.objectId is null when debugging but has a value when looking at it from backendless (manually added in backendless).
I’m not aware of any other way to add users as a related object other than Add Column -> Data Object Relation -> and select the table as Users (system table).
Let me know if there is any other information you guys may need.
EDIT: Looks like all properties of relational object fields are null in PictureModel when retrieving one yet they have values in backendless which may be the problem.

Stephen,

Could you attach a screenshot of your PictureModel table schema to give us a better idea of what you have?

What is the data type of the model.UserID field/property?

Regards,
Mark

Ok so I’m almost certain the problem has to do with all the relations being null. Now looking at the object relation tutorial I’ve attempted the following code:

BackendlessDataQuery query = new BackendlessDataQuery();
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated(“UserID”);
query.setQueryOptions(queryOptions);
Backendless.Data.of( PictureModelNew.class ).find(query, new AsyncCallback<BackendlessCollection<PictureModelNew>>() {
@Override
public void handleResponse(BackendlessCollection<PictureModelNew> pictureModelNewBackendlessCollection) {

}

@Override
public void handleFault(BackendlessFault backendlessFault) {
}
});

And now I’m getting the error:

“Unable to adapt array to data type: class com.selfit.main.models.Users”

It looks like you created your own Users class. This is not a good idea with Backendless. Instead you should use the BackendlessUser class. Make sure to change the data type for the UserId property (that was my 2nd question) to BackendlessUser.

error-saving-object

in my case i just need to updape a Job.class

Hey julio

You can find how to update Data Objects here https://backendless.com/documentation/data/android/data_updating_data_objects.htm

Regards, Vlad