I have two entites: Folder and Picture. A Folder can have many Pictures, and a Picture can belong to many Folders. However, there is one Folder called All, which holds all pictures belonging to any folder. So the Folder entity has a to-many relationship with Picture, so that each Folder has an NSSet of Pictures, and also each Picture has an NSSet of Folders. The All Folder contains all Pictures, but I don’t want any Picture to have the All Folder as one of their Folders.
Currently with the way my model is set up, if I add a Picture to the All Folder, the All Folder is automatically added to the Picture NSSet of Folders, which I don’t want. I think this happens because I have the two relationships as inverses of each other. But if I don’t select the inverse option, my Picture entities begin only supporting one Folder instead of many.
The question is: how can I model my entities so that A Folder can have many Pictures, and Pictures can have many Folders, but if I add a Picture to a Folder, it shouldn’t necessarily mean that that Folder is added to the Picture.
Here’s my current model:
Picture:
Relationship: Folder
Destination: Folder
Inverse: Picture
Plural: To-Many Relationship
Folder:
Relationship: Picture
Destination: Picture
Inverse: Folder
Plural: To-Many Relationship
Why do you need an All folder at all? Is “All” its own entity, or is it a Folder entity with some sort of All identifier?
Either way, if you all you want is to grab all the pictures in any folder, you can do that pretty simply with a fetch request. No need to muck up your object graph with an extra entity or relationship.