Re: CoreData: filtering controller content
Re: CoreData: filtering controller content
- Subject: Re: CoreData: filtering controller content
- From: Justin Fagnani <email@hidden>
- Date: Wed, 1 Jun 2005 17:55:37 -0700
I've hit a problem with my goal of having a list of all objects not
an ancestor of the selected object of a NSArrayController.
I created ManagedTreeObject with has these methods:
- (NSSet*) descendants;
- (NSSet*) descendantsAndSelf;
- (NSSet*) ancestors;
- (NSSet*) ancestorsAndSelf;
and they work fine. The problem is that I want a list of entities
that are *not* ancestorsAndSelf. I was hoping to use ancestorsAndSelf
in the predicate of a NSArrayController, but I can't figure out how
to wire it up. I would imagine the predicate to be something like this:
not in Types.selection.ancestorsAndSelf
but that's not valid.
Another though is to implement notAncestor: but I'm not sure how to
do that either, since I'd need access to objects that are not
connection through parent or children.
Any suggestions would be great.
Thanks,
Justin
On May 28, 2005, at 11:08 AM, Justin Fagnani wrote:
I have some data that's very much like a class hierarchy. Each
object has a parent. I have a pop-up button for selecting the
parent, but I'd like to remove the target object and any of it's
descendants from the list so that there's no possibility of loops.
I guess this is similar to the question I asked a little while ago
about getting all descendants in an NSTreeController[1], and will
probably have a similar solution, but I've been trying to figure
out ways to do this with out writing code using just an additional
controller and predicates.
What I think I'm finding is that the predicate syntax is not as
well suited for working with trees as other expression languages.
XPath, for instance, has the ancestors and descendants axes.
I actually can't even figure out how to filter out the object I'm
editing from the list of types. The object is selected in an
ArrayController called Types. I want a second ArrayController
called ParentTypes to contain all the valid choices for a parent. I
figure that I could filter the selected object with a predicate of
"self != ????" well, what do I put there? Types.selection? The
predicate builder for fetched requests has a way to place a
variable in the predicate, but I can't seem to compare self to a
variable. And the predicate for a controller doesn't have a GUI, so
I'm not sure yet how to place a variable. Even then, how do I set
that variable?
So this leads me to another solution where I subclass
NSManagedObject and create a property called something like
objectsNotSelfOrDescendent. To save some work I can add this to my
previous subclass and call it a ManagedTreeObject. Ok that's not
too bad I guess. However, for some reason I think of this as really
extending the behavior of the controller. I'm tempted to subclass
NSTreeController and add methods for retrieving objects along the
different axes. Good idea or bad idea?
Any thoughts on this?
Thanks,
-Justin
[1]: http://www.cocoabuilder.com/archive/message/cocoa/
2005/5/24/136900
_______________________________________________
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