Re: Fun (or not) with NSArrayControllers and CoreData.
Re: Fun (or not) with NSArrayControllers and CoreData.
- Subject: Re: Fun (or not) with NSArrayControllers and CoreData.
- From: Quincey Morris <email@hidden>
- Date: Wed, 29 Jul 2009 15:25:11 -0700
On Jul 29, 2009, at 14:30, Daniel DeCovnick wrote:
I'm sorry, you misunderstand. My NSManagedObject subclass Folder,
not Job, has the allDescendantsJobs, and the NSTreeController/
NSOutlineView has all Folders where parent==nil as its root objects.
There is a one Folder to many Jobs relationship. Folders and their
children (and their children, etc.) show up in the outline view, and
there's a table view of Jobs for the selected Folder (and, ideally,
it's children).
snipped...
I don't think very much of that still applies given the
misunderstanding above.
Yeah, well, I think it all still applies. You have a tree-structured
data model and you want to add to each non-leaf root node a property
that's a to-many relationship to all its (directly or indirectly
descended) leaf nodes. Yes? I may have had the class names wrong, but
that's what I was talking about.
Try this:
-- Add an "allDescendantJobs" Core Data to-many relationship to the
Folder entity in your Core Data model. Set its delete rule to Nullify.
-- Add a "rootFolder" Core Data to-one relationship to the Job entity,
and make it the inverse of "allDescendantJobs". Set its delete rule to
Nullify.
-- Whenever you add a Job object to a Folder, also set the rootFolder
property:
addedJob.rootFolder = [parentFolder ... find its root folder
recursively or whatever ...]; // this is KVO compliant for both ends
of the relationship
-- Bind a NSArrayController in entity mode to the "allDescendantJobs"
property of whatever represents the selection in the Folders outline
view.
-- Bind the Jobs table view to this array controller.
Now it should work. The only problem is going to be that the user
interface may update for *each* Job object that's added/removed, which
is less than optimal if you're updating a lot of them. And you're
keeping an extra pair of relationships in the persistent store. If you
need to avoid either of those things, you're going to have to work
harder.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden