NSTreeController / CoreData quesiton
NSTreeController / CoreData quesiton
- Subject: NSTreeController / CoreData quesiton
- From: Justin Fagnani <email@hidden>
- Date: Tue, 24 May 2005 13:48:08 -0700
I'm wondering how to model and bind this particular scenario...
I have some hierarchical data with two classes: Category and Item.
Categories are nested and have only one parent, Items belong to only
one Category. Eventually I want an NSBrowser to contain the
Categories and a table to show all the items that are descendants of
the selected Category(s).
So far my model looks like this:
Category
parent <<--> Category (inverse w/ children)
children <-->> Category
items <-->> Item (inverse with Item.category)
Item
category <<--> Category
I have a NSTreeController setup with a predicate of parent == nil and
that seems to work pretty well. The problem is getting all the
correct items. I can get the direct items of the selected Category,
but not the Items it's child categories contain, and so on.
I'm thinking that Category.items maybe should be a fetched property
instead of a relationship, but I don't know how to write a predicate
that says "category or category.parent or category.parent.parent...
== selectedCategory". I'm actually not too sure how to directly
compare objects, I'm just using names.
here's my other ideas:
*Subclass NSManagedObject for Category and use a recursive method for
getting all the items.
*Do the same for Item, but it returns all ancestor categories as a
set. This could maybe be used in a predicate like "selectCategory IN
item.categoryPath" (though l'm not sure I can even get the selected
category into a predicate statement)
*Have Item.category be a to-many relationship that links to it's
direct category and all it's ancestors, but this seems fragile.
Any thoughts?
Thanks,
Justin
_______________________________________________
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