Backendless Support
 
Trying to Reproduce

losing relationship on user update

I have a one to one relationship from the "users" table to a table names "member". When I update a user via Backendless.UserService.update(user) it is wiping out my member relationship. This worked in 3.0 but seems to behave differently in 4.0.

SocialTeeTimeV2

AppId: C25CB2C7-149D-F6DC-FF86-AEE62D080B00

Leave a Comment

Comments (21)

photo
1

Hi Dan,

Establishing and deleting relationships in Backendless 4 works differently than in 3.x. Please see the documentation for details:

https://backendless.com/docs/android/doc.html#related_objects

Regards,

Mark

photo
1

Hi Mark,

I did see that. However, this was an established relationship from the 3.0 to 4.0 migration. Then once the relationship was lost i manually recreated the relationship which was also lost when updating the user.

photo
1

Hi Mark,

Let's ignore this issue for now...I'm sure it has to do with the new way we now have to create relationships (which btw I really like...make sense). I restructured my code to match the new way.

1) I'm now getting a 500 error which states the error was sent to your team. Most recent error id: 70736CCC-9549-CA5A-FF51-CB75D8DC7200

2) The new way of saving relationships requires that both the parent and child objects must be in backendless storage. If the parent object has the child relationship defined as required how can the parent object be in backendless storage with out the child relationship being set/added? I hope this makes sense.

Thanks,

Dan

photo
1

Hi Dan,

1. How can we reproduce the 500 error? Please describe steps to reproduce.

2. You're correct, it would not be possible - we will be removing support for required for relations in the upcoming build.

Regards,

Mark

photo
photo
1

Hi Mark,

So I'm still confused about Backendless.UserService.update(user). I'm trying through code to update the email address. When calling the update method it wipes out an existing relationship.

Dan

photo
1

Is this in 4.0 or 3.x?

photo
photo
1

To clarify, I load the user using Backendless.UserService.getCurrentUser() which I'm assuming loads the relationship in question. I then update the email address and call Backendless.UserService.update(user). This works successfully but in the database my relationship is gone.

THanks,

Dan

photo
1

Are you using Android SDK? The reason I ask is the method in Android is "Backendless.UserService.CurrentUser() and not "getCurrentUser()"

photo
photo
1

version: 4

I'm using the javascript SDK.

I'll remove the required constraints on my relationships.

Regarding on how to reproduce, do you want me to send my code? In the end I (this is a repeat from above) call Backendless.UserService.getCurrentUser, update only the email address, and then I call Backendless.UserService.update. I pass the entire user object in the "update" call. I guess I could just pass the objectId and email address...right?

photo
1

Dan,

I will create a test user account with some relations in your app and try as you said:

  1. login user
  2. call getCurrentUser
  3. Update email
  4. save the user object

Does it sound like a valid use-case to reproduce the problem?

Regards,

Mark

photo
1

Update: I just passed in the user table objectId and email address and everything worked as expected. In 3.0 i was able to pass in the entire object (including relationships) without a problem. So all is good on my end...not sure if you still consider that a defect though. I think I good my issues crossed with this error and the 500. Let me make sure my code looks ok and then I'll get back to you. Stay tuned.

photo
1

Check out my recent reply.

photo
1

Hi Dan,

do you see lost relationship of user in Admin Console? Just to clarify if the relation was lost in DB or while passing updated user object to client.

photo
1

Yes, after I call the update method with the entire user object I can see the lost relationship in the Admin Console. Does that help?

photo
1

Dan,

Could you please clarify: are you saying you can see the relationship in the console, but it is not returned back to you in the response for the update api call?

Mark

photo
1

Ha, it's hard through text sometimes. So, after the update i can no longer see the relationship in the console nor does it come back in the response

photo
1

Here's a video where I update an object property with the Update call. Relationship I had prior to update stays with object in console:

https://monosnap.com/file/W5fcZT0ZQar64Te3uX5U7YmZwceOzc

photo
1

Hi mark, i think you can close this out. thanks for your help.

photo
1

Hi guys, I'm confusing with updating of user(( Relationship is losing(

I read your docs with relationships, but I still can't understand.

Please look at the video: https://www.dropbox.com/s/n5dqjbgvtac7tbj/user_saving.mov?dl=0

You can download it for better quality.

Before update I has Contacts and devices and after they are missed.

If it's default behaviour, what the sense to return an object with missed fields.

photo
1

Hi Oleg

Yes, it's default behavior. When you update user object the server returns only plain properties without relations

I can propose you a few workarounds:

- keep relations in another variable

- reload relations in the next api call

- use Business Logic, create an Event Handler "afterUpdate" and in the handler extend updated object with relations what you need

Regards, Vlad

photo
1

Thank you for your reply!

Just for comparing:

v.3

  1. BackendlessUser updatedUser = Backendless.UserService.update(user);

v.4

  1. Object[] devicesObjectArray = (Object[]) user.getProperty(Consts.DEVICES);
  2. Object[] usersObjectArray = (Object[]) user.getProperty(Consts.CONTACTS);
  3. BackendlessUser updatedUser = Backendless.UserService.update(user);
  4. updatedUser.setProperty(Consts.DEVICES, devicesObjectArray);
  5. updatedUser.setProperty(Consts.CONTACTS, usersObjectArray);

photo