I’ve got three entities in my application so far: tag, feed and story
A tag has got a to-many relationship to feeds and feeds has got a to-many relationship to story.
I’ve got an NSArrayController for each entity, one named tags, one named feeds and one named stories.
They all share the same ‘managedObjectContext’ which they get from the file’s owner. the content set of the AC named feeds is bound to ‘tags’ controler key: selection, key path: feeds
I want the content set of the third array to be bound to all of the stories in all of the feeds in the selected tag: i tried to use the key path: “@unionOfArrays.stories” but couldn’t get it to work.
Any idea how i would go about this?
First of all, there’s one thing in your question that’s inconsistent with getting something working:
When I set this up in IB, it just didn’t work. You surely mean you bound the managedObjectContext to that of the App Delegate.
Assuming you want to see all the stories in the selected tag, here’s a few mistakes you might have made in your setup.
1. Check Inverse Relationships
For all the relationships you mention, you need to set the inverse for each relationship.
For the one to many tags->feeds relationship, you’d have a to many relationship in the tags elements called “feeds”, which you’ve described.
You’d also have a to one relationship in the feeds entity called “tag”.
You’d select the inverse relationship as being feeds as shown below:
Single Feed Relationship http://img20.imageshack.us/img20/2557/tagsinglefeedrelationsh.jpg
2. Link Up Stories
You don’t mention how you’ve created any of your Stories. Assuming you’re not doing anything in code, I’d have 4 Array Controllers:
If you just have a Stories Array Controller whose Content Set isn’t bound to anything, you’ll be creating stories effectively in a vacuum – they won’t be linked to any feeds or tags, which might be why you’re getting these errors.
3. Setup “Stories in Selected Tag” Controller
You need to set the Content Array, not the Content Set.
Bind the Content Array to the “Feeds in Selected Tag” Controller.
This sends the Key Path stories to every object in the “Feeds in Selected Tag” Controller, thus getting all the Stories in all the Feeds in the selected Tag.
4. Rock and Roll!
We’re done. If you’re really struggling getting this set up, let me know and I can post the link to the XIB file I’ve made.