Parse.com includes related objects in one to many relationships

Presumably I have a database structure like this

Person ('name', 'age')
Belonging ('person', 'type')

      

with his attitude like this

Person -> Belongings (one to many)

      

and I want to ask all people for their number of things included like this

Array[0] -> name, age, numberOfBelongings,
Array[1] -> name, age, numberOfBelongings,
etc

      

How should I do it? I tried using CloudCode , but it turns out that the fetch method is asynchronous, so I can't get the number of things for each person.

0


source to share


1 answer


You cannot do this directly. If you need this account, you can create a Person class field (i.e. Numeric value) that you update in the afterSave cloud code binding on Belonging. Whenever Save is saved, you also increase the number of fields of the alternate Person objects and save them.



No extra requests, no extra network traffic from your device, and you always have a counter for any Person object.

+1


source







All Articles