Backendless Support
 
Answered

Relations are not being set (iOS)

      I am creating an object with the following code:

      1. Comment *comment = [Comment new];
      2. comment.text = commentTextView.text;
      3. comment.author = backendless.userService.currentUser;
      4. comment.event = self.event;
      5. id<IDataStore> commentDataStore = [backendless.data of:[Comment class]];
      6. [commentDataStore save:comment response:^(Comment *savedComment)
      7. {
      8. } error:^(Fault *fault) {
      9. NSLog(@"Fault saving comment: %@", fault.message);
      10. }];

      As you can see, I am setting two relations:author and event, but neither is successfully being set. The object is being created and the text property is correct, but nothing for either realtion.

      Thanks.

      Leave a Comment

      Comments (4)

      photo
      1

      Hello,

      Establishing relations between objects works differently in Backendless 4. Both the parent and the child(ren) objects must exist in the database at the time when a relation is created (which is done via a separate API call). For more information, please see the developer documentation:

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

      Regards,

      Mark

      photo
      1

      Mark, if you don't mind, what was the motivation behind making that change? It seemed extremely counter-intuitive and slow. I'd love to know how it is improvement.

      Thanks

      photo
      1

      Hi Cooper,

      It feels different because you're familiar with how relationships were created in 3.x. Indeed, setting up a full hierarchy and saving in a single shot is simpler, however, it caused numerous scalability problems on the server side, especially for apps with higher concurrency. Additionally, deleting relations in 3.x was very problematic. One had to load an object with ALL relations, remove the ones you do not need and then re-save the object. The same is true for updating a set of relations. The entire system was improved by introducing a completely new set of APIs dedicated to relationship management. If you think this will cause extra API calls, that's not necessary true. Here's a complete comparison between 3.x and 4.x for the number of API calls required:

      http://support.backendless.com/topic/relations-management-with-backendless-4#comment-28982

      Regards,

      Mark

      photo
      1

      Got it! Thanks for your explanation, Mark! Very helpful. Unfortunate for cases which require multiple relationships to be set... but I'm all for speed (as speech is probably my biggest problem with Backendless currently). Again, I appreciate the response.

      photo