Re: CoreData and multiple to-many relationships
Re: CoreData and multiple to-many relationships
- Subject: Re: CoreData and multiple to-many relationships
- From: John Timmer <email@hidden>
- Date: Thu, 20 Oct 2005 10:59:58 -0400
- Thread-topic: CoreData and multiple to-many relationships
> I have a document-based CoreData application which has (among others)
> two Entities: Entry and Category. Entry has a to-many relationship to
> Category known as categories. Category also has a to-many
> relationship to Entry known as entries. So an entry can have any
> number of categories, and (of course) a category needs to know of
> many entries.
>
> My problem comes from application logic. Category assignment happens
> from a drawer which has a list of all the categories and the controls
> to add and remove them. The list (a NSTableView) has two columns, one
> for the category name and one with checkboxes so the user can select
> which categories the selected entry belongs to. My problem lies in
> this single column. I cannot figure out the binding for that column.
> The entries and categories are managed by NSArrayControllers known as
> EntriesController and CategoriesController respectively.
>
> I've been fumbling with this for a while now and cannot figure it
> out. Anybody have an idea for a solution?
I don't think you can actually bind this. To convert this appropriately to
a boolean (which is what the checkbox needs), you'd need to know both the
Category value and the Entry value (to check if the category is part of its
set of categories, and to add/remove it when changed). Value transformers
are handed only a single object, so there's no obvious way of obtaining both
types of information.
The one option I can think of is to wait until after the document's nib is
opened to instantiate a custom value transformer, and hand that a reference
to the NSArrayController that will register the selected Entry that this
table view is displaying. You can then bind to the Category through your
value transformer. This would make the value transformer pretty fragile
(prone to breaking if you change the interface or object model), but it
might be workable.
JT
_______________________________________________
This mind intentionally left blank
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden