Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 97: Update object’s related collections using API
April 15, 2015 by markpiller
Spread the love

Data objects stored in Backendless may have related objects through one-to-one or one-to-many collections. When objects are retrieved on the client side, these relations are materialized as collections of data in object’s fields or properties. Consider the following data object:
person with related addresses -  Feature 97: Update object's related collections using APIThe Person table has the addresses column which is a one-to-many collection with the Address table.The Person table schema is:
person schema with address -  Feature 97: Update object's related collections using API

The related Address objects are shown below:
related addresses -  Feature 97: Update object's related collections using API

At the code level, there is Person class defined as:

And the related  Address class is defined as:

The code below loads the Person object with the related Address objects. It prints out the number of Address objects, deletes one from the collection and saves the Person object back. Once it is saved and the updated instance is returned, the code prints out the number of related addresses to confirm one was indeed deleted:

Asynchronous API sample: (Android and Plain Java):

Synchronous API sample (Plain Java only):

The code produces the following output:

It is important to note that Backendless supports any kind of relation update. Your code could add new related objects, remove some (as shown above), change data inside of the related objects, etc. All of these changes will be persisted when the parent (Person) object is saved.

Enjoy!

 

 

Share this post
Tweet about this on TwitterShare on FacebookGoogle+