Backendless Support
 
Answered

Relation in api version 4

Hi all,

https://backendless.com/documentation/data/android/data_relations_save_update.htm

  1. Address address = new Address();
  2. address.setStreet( "TN 55" );
  3. address.setCity( "Lynchburg" );
  4. address.setState( "Tennessee" );
  5. Contact owner = new Contact();
  6. owner.setName( "Jack Daniels" );
  7. owner.setAge( 147 );
  8. owner.setPhone( "777-777-777" );
  9. owner.setTitle( "Favorites" );
  10. owner.setAddress( address );
  11. PhoneBook phoneBook = new PhoneBook();
  12. phoneBook.setOwner( owner );
  13. PhoneBook savedPhoneBook = Backendless.Persistence.save( phoneBook );

This code does not work for api v4, it store all objects, but without relations.

Please explain how I should modify it to work for api v4?

or do you plan to leave only addRelation method?

thanks

Leave a Comment

Comments (7)

photo
1

Please see the version 4 documentation (link below. The link you have is for the 3.x docs.

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

photo
1

is there is way to store relations+data within one transaction? and rollback changes if transaction can't be finished?

photo
1

Only if all objects are already in the database.

photo
1

in other words, mobile app will corrupt the db if we will use it directly...

photo
photo
1

and how to solve concurrency issue(one user/app trying to add new relation and second user/app also trying to add/update relation )? as I see, second request will drop data from the first one

photo
1

What do you mean by "if you use the db directly"?

And how can you update a relation which doesn't exist? Outside of that, the last request wins.

photo
1

You can also group requests to db in one business logic method on the server side.

By transmitting to it the necessary set of parameters, you can delegate him duty to communicate with db and to monitor the integrity and consistency according to you logic.