ios - CoreData fetch nested objects -


i have json contain objects each object have child object, example

[     {         "id": 1,         "name": "obj1"     },     {         "id": 2,         "name": "obj2"     },     {         "id": 3,         "name": "obj3",         "child": {             "id": 2,             "name": "obj2"         }     },     {         "id": 4,         "name": "obj4",         "child": {             "id": 5,             "name": "obj5"         }     } ] 

so in core data have entity myobject has relation child (to itself, one), , relation parent (to many)

enter image description here

so when try fetch object predicate like

[nspredicate predicatewithformat:@"parent.@count = 0"] 

i got object id in [1,3,4], no id = 2 (here error) , id = 5 (here correct), because it's sets parent when it's mapped when object id = 3 save data base.

if no use predicate got 5 object, include obj5.

but need fetch coredata count of object got json.

i need fetch object id in [1,2,3,4].

how need write predicate, if it's possible?

the data got json subset of objects, logic according selected not persisted in object model.

you persist relationship between child , parent (hint: readability, rename parents if to-many), selection in json example not based on of criteria.

one easy way objects extract top level ids delivered json feed , use in predicate:

nsarray *ids = [jsonarray valueforkey:@"id"]; [nspredicate predicatewithformat:@"idnumber in %@", ids]; 

(note changed attribute name id idnumber in order avoid possible language quirks, id reserved word.)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -