Hi, i’m using backendless in my iOS app. I want to know if there is any efficient way of appending an item on a one-to-many relation data object. The way I do it is ,
var items = user.getProperties("Item")
items.append(newItem)
backendless.userService.update(user)
This seems very inefficient because you are retrieving the whole array of objects that might have potentially huge size just to add an element. Is there any efficient way of achieving this purpose? THanks.
Hi Chan,
There is a way to do it more efficiently (without loading all the children). This topic was just discussing in another thread. Please see it at the URL below, there is an example for the approach that can be used to accomplish what you’re looking for:
http://support.backendless.com/t/linking-related-data-using-client-api
Regards,
Mark
I don’t see how the link you provided relates to my question. If I follow the example in the link, I would just overwrite what I have on ‘Item’ property
So, I don’t have user.items on my local memory. I can’t just do the below example if I don’t have ‘user.items’ right?
user.items.append(newItem)
backendless.data.of(BackendlessUser.ofClass()).save(user)
as far as I know, if user.items is empty, line 2 would just overwrite all my child classes for item.
The link describes the approach where you use NSDictionary (rather than a custom type) to represent the “parent” object. In that dictionary you populate the “objectId” property to identify the object. Then you also add another property for the relation. The relation value will be an array containing the child object you need to add to the related collection. The child object must also be represented via NSDictionary. It is important that the child object contains the “___class” property with the value identifying the name of the table where it should be stored.
No, line 2 will not overwrite what you already have in the persistent storage, it will append to it.
Thank you. I tried it and it really doesn’t overwrite it!