Core Data question modeling Hierarchical Data with a Container
I'm trying to set up a hierarchical data model with a container in Core Data. Here's my model so far:
Container
1-* rootNodes <Nodes>
Nodes
1-1 parentNode <Nodes>
1-* childNodes <Nodes>
However, I got this error: Container.rootNodes -- to-many relationship does not have an inverse: this is an advanced setting (no object can be in multiple destinations for a specific relationship)
So, I created an inverse relationship on Nodes, thusly:
Nodes
1-1 parentNode <Nodes>
1-* childNodes <Nodes>
*-1 container <Contain开发者_高级运维er>
However, this isn't quite correct. I don't want my container to have a relationship with nodes, just the root level nodes.
I'm a bit hesitant to complicate my data model too much, but now I'm thinking it may be necessary. If I move a child node to a root level, I don't want to have to worry about casting types, etc. However, I understand I am working with two different sets. Root nodes, and all other nodes.
Here is my proposed data model, but I am looking for a better suggestion:
Container
1-* rootNodes <Nodes>
Nodes
1-1 parentNode <Nodes>
1-* childNodes <Nodes>
RootNodes : Nodes
*-1 container <Container>
Is this correct?
Is there something in Container that is needed that the Nodes don't have? From what I see the only reason for Container is that you may be looking at Container as a launching point to get your Nodes. If this is true then you may be able to remove Container completely and get the root Nodes by using a predicate filter with a search criteria as "parentNode is NIL".
The Inverse Relationship message is just a warning. Apple's perspective is that all relationships need to have an inverse and it is worth strong consideration before going against it. But this is only a warning and things will still run ok if you're careful. This warning can be suppressed if you choose by going your target build settings finding the section Data Model Compiler (MOMC) - Warnings. Then find the entry for "Suppress momc warnings on missing inverse relationships" and check the box.
Rob
精彩评论