Backendless 4 Issue with Data Relation Saving in iOS

Hi,
I just created a new application using the backendless 4. But I am looking at the data relations in the tables for backendless 3 and 4 and it looks like there is too much overhead in the new system.
Here are the relation details :
http://image.prntscr.com/image/50fe8350cc774243b5c1f0290cd9ff7b.png</img>
http://image.prntscr.com/image/8bf9964bffeb4c4492146c57f1c340b4.png</img>
Here is the ERD
http://image.prntscr.com/image/c28c4aad37934addb306cfbef7c806a6.png</img>
The issue is in the old backendless 3, i just have to add create a new object for the MyOils class and add it in the property of Backendless user object then I just have to call 1 server call and it all gets saved to the server with proper relations. With following code:

MyOils *newOil = [MyOils new];
 newOil.MySingleOil = self.singleOil;


    [allMyOils addObject:newOil];
[updatingUser setProperty:@"MyOils" object:allMyOils];

BackendlessUser *updatingUser = backendless.userService.currentUser;[backendless.userService update:updatingUser response:^(BackendlessUser *updatedUser) {

backendless.userService.currentUser = updatedUser;

} error:^(Fault *error) {}];







But in the Backendless 4 , I have make 4 server calls to get the same effect. With following code:


MyOils *newOil = [MyOils new];
 id&lt;IDataStore&gt; dataStoreMyOils = [backendless.data of:[MyOils class]];
 [dataStoreMyOils save:newOil response:^(MyOils* newSavedOil) { 
 [dataStoreMyOils setRelation:@"MySingleOil" parentObjectId:newSavedOil.objectId childObjects:@[self.singleOil.objectId] response:^(NSNumber *number) {
 id&lt;IDataStore&gt;dataStoreUsers = [backendless.data ofTable:@"Users"];
 [dataStoreUsers setRelation:@"MyOils" parentObjectId:backendless.userService.currentUser.objectId childObjects:@[newSavedOil.objectId] response:^(NSNumber *num) {
 [backendless.userService findById:backendless.userService.currentUser.objectId response:^(BackendlessUser *latestUser) {
 backendless.userService.currentUser = latestUser;
 } error:^(Fault *error) {}];} error:^(Fault *error) {}];} error:^(Fault *error) {}];} error:^(Fault *error) {}];


My Question is is this all correct?
Do I have to call the server 4 times now to get this working?
Or Am I missing a better way for that?

Hi Umer

Thanks you for your question.

Yes, in 4.x you can not do that in a single request, you can add only exists(stored on the server) objects as relations to another exist object.

So, you can do 4 request:

  1. create/save SingleOil
  2. create/save MyOils
  3. add saved SingleOil to saved MyOils
  4. add saved MyOils to user

Or, I can propose you to use BusinessLogic for it, you can implement it via EventHandlers or APIServices

below you can see links for BL docs,

EventHandlers docs:
https://backendless.com/documentation/business-logic/js/bl_data_service_handler.htm

APIServices docs:
https://backendless.com/documentation/business-logic/js/apieng_quick_start_guide_js.htm

APIServices video:
https://www.youtube.com/watch?v=gmfk6tbb-Ns

Hope it will help you.

Regards, Vlad

Hi Vladimir U

Ok got your point.

Thanks for the quick reply.

Hopefully you guys will be working on this in the future as it seems to be real big overhead for now.