Fault: Adding users as related objects

Creating a custom object like so:

 let friendship = Friendship(members: [currentUser, selectedUser])

which used my custom init:

 init(members: [BackendlessUser]) {
 self.members = members

and then saving it like so:

 backendless.persistenceService.of(Friendship.ofClass()).save(self, response: { (savedFriendship) -> Void in
 print("successfully saved friendship")
 completed(fault: nil)
 }) { (fault) -> Void in
 print("Server reported an error: \(fault)")
 completed(fault: fault)

But at times I get back:

Server reported an error: Server reported an error: FAULT = '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.]  ULT = '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.] 

Sometimes it works, most other times it doesn’t. Here’s the friendship object right before I save it:
I feel like I’m adding the users as relations properly to the custom friendship object, so not sure why I’m getting a fault.

Is it possible the “members” array might be getting a user object which has not been registered before? This would cause the error you’re seeing.

The only way I’m creating users is through registering users with the User API so I don’t believe that is the case. It’s odd because sometimes I get he fault; sometimes I dint

Where does the “currentUser” object come from?

currentUser is retrieved by querying for a specific User via an objectId (which I get from backendless.userService().currentUser).

The reason I have to get currentUser by this query (as opposed to just using userService.currentUser) is otherwise the relatedProperties on it are empty.

I see, thanks, Vik. I assume you recently updated the library from the github repo. To rule out any regression in it, may I ask you to download the library from our website (instead of git) and see if that use-case works with that version?

I tried with the other library and I get the same error back.

It works when the currentUser has no data in its friends property (which a relation to many other Users). But then when the currentUser has values on that property it gives me that error.

Thanks, this is helpful. Could you please provide a screenshot (or more than one if it does not fit) showing the “friends” property expanded?

No problem; here you’ll see one user has friends while the other doesn’t (which is correct according to the data on my console):

It is only when the currentUser has friends (on the console database) that it will not work.

Am I wrong or that BackendlessUser object in “friends” looks like it has not been initialized (does it have any properties?)



When I log out the value of the user you’re referencing, it appears to be initialized:



I see there are three users: “tom”, “chris” and “vik”. In the first screenshot “friendship” is between “tom” and “chris”. In the last one “chris” is in the “friends” list of “tom”.

Could you describe what combination of members in a Friendship and their corresponding friends causes the error?

As I mentioned all my users are created by registering via the User API so I don’t see how any of them could not be registered

There is no doubt we’re dealing with a bug on our side. I just want to make sure we’re reproducing it using the same data structure as yours.

Yes, I currently have two friending architectures in place. Friendship objects and then also a friends relation on a User.

It’s only when a user’s friends property is not empty and they are added as a member to a friendship object that the friendship object fails to save.

Can someone suggest me soultion to this ?

Solution to what?

for error 8011 that is “Users can be added as related objects…”. I am trying with users with valid object id and also users are created using User API.

You cannot CREATE new user as related object - you must REGISTER it previously.