Core data many to many asyn downloads
I'm trying to get my head around core data. I have a many to many structure with the following:
Entities: Tree <->> TreesLeaves <<-> Leaf
Relationships: treesLeaves <->> trees / leaves <<-> treesLeaves
I have 2 download pr开发者_如何转开发ocesses one that downloads trees and one downloads leaves. I start by downloading the leaf data. Inside each leaf are reference IDs which are TreeIDs.
When I download the leaves data I create the leaf and TreesLeaves objects and save them to Core Data. This also starts the download of the Trees data.
My question is once the tree data has downloaded how do I get reference back to the TreesLeaves object so that I can update its trees relationship?
Thanks
You will be looking for specific existing TreesLeaves
objects based on some property value of those objects. Therefore, you find them with a fetch whose predicate is configured to find objects with those specific property values.
Update:
so is the best approach to add an additional attribute inside TreesLeaves such as the treeID to gain reference to it?
I don't know because I don't know anything about you data model other than what you have provided. I don't know what your trying to do or why you've configured the data model the way you have.
If TreesLeaves does nothing but link the two other entities then you can and should make a new one for each relationship. If you alread have the Leaf<-->>TreesLeaves
relationship set, then you would be fetching based on some property of Leaf
.
The idea here is that there is some property of specific Tree
objects that link them to specific Leaf
objects and vice-versa. You fetch on those properties.
Why are you using TressLeaves
instead of just creating a relationship directly from Tree<<-->>Leaf
? You would usually only use that and intervening linking entity if you want some kind of arbitrary ordering.
精彩评论