I am making app where I want users to add other users as friends. I have set up one to many relation for Users in my Users table and I am struggling with reading the friend list and updating it, here is my code and error messages :
How do I update the existing users, here is the code I use now:
BackendlessUser user = Backendless.UserService.CurrentUser();
ArrayList<BackendlessUser> friends = new ArrayList<BackendlessUser>();
friends.add(userThatIwantToAdd);
user.setProperty(BackendlessUserProperties.FRIENDS, friends);
Backendless.UserService.update(user, new DefaultCallback<BackendlessUser>(context) );
But for unknown reasons to me, I get this error
1. BackendlessFault{ code: '1007', message: 'Unable to save object - invalid data type for properties - friends. You can change the property type in developer console.' }
So can you please point me in the right direction, is it possible to add BackendlessUser object to others or do I have to make a column that remembers just their objectIds or something? I have the relation working with GeoPoints without any problems, I am not sure why this doesn’t work.
Second problem is getting the list of friends, here is the error I get.
java.lang.Object[] cannot be cast to java.util.List<com.backendless.BackendlessUser>
And this is my code:
BackendlessUser user = Backendless.UserService.CurrentUser();
List<BackendlessUser> pendings = (List<BackendlessUser>) user.getProperty(BackendlessUserProperties.PENDINGS);
I tried to cast the Object[] but it doesn’t work. I also searched the support forum, and I have found this code snippet, that should solve the second problem, but it doesn’t even tough I have included it right after the initApp() call.
Backendless.Data.mapTableToClass("Users", BackendlessUser.class);
I am new to Backendless so it may be a stupid mistake or the api changed because this snippet is from a year ago, and that could be the reason why it doesn’t work. Note that autoLoad is checked for the friends column in Users table.