Support Topics Documentation Slack YouTube Blog

Relations are not being set (iOS)

(Cooper Edmunds) #1

I am creating an object with the following code:

Comment *comment = [Comment new];
comment.text = commentTextView.text; = backendless.userService.currentUser;
comment.event = self.event;
id<IDataStore> commentDataStore = [ of:[Comment class]];
[commentDataStore save:comment response:^(Comment *savedComment)
} error:^(Fault *fault) {
NSLog(@"Fault saving comment: %@", fault.message);

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.

(Mark Piller) #2


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:


(Cooper Edmunds) #3

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.


(Mark Piller) #4

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:


(Cooper Edmunds) #5

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.