Thanks for the reply Melissa - much appreciated.

I was beginning to toy with the idea of trying a function expression (which I have used before for other purposes) to isolate an individual attribute object and perform the several comparisons therein. Presumably SUBQUERY, being designed for the job, benefits from some performance advantages over the function approach(?).

Regards

Luke



On 8-Dec-08, at 2:07 PM, Melissa J. Turner wrote:


On Dec 6, 2008, at 01:45, Luke Evans wrote:

If there are any NSPredicate gurus out there, I'm scratching my head on this one:

I have an entity that can optionally have a set of attributes (name- value pairs). This is set up in the model as a optional to-many relationship to an attribute entity. Now, I want to fetch the list of managed objects of this entity whose attributes exactly match a dictionary that is passed. The predicate for this needs to filter the objects that have all the required attributes; matching both the name, and value for each attribute.

At this point I'm not seeing how you can code this in a predicate. If I AND some clauses like:
...ANY attr.name == %@ AND ANY attr.value == [EMAIL PROTECTED]
for each attribute I'm testing for, then AFAICS I'm not testing that the _same_ attr has the name and value.

I wondered about:
...ANY (attr.name == %@ AND attr.value == %@)...
but this doesn't appear to be legal syntax.

I'm still experimenting, but if anyone knows how to express a query that allows multiple clauses on the _same_ entity across a to-many relationship I'd appreciate a clue!

Cheers

Luke

If you're targetting 10.5 or later, there's a subquery expression in the predicates that was added to support this kind of query. The syntax for what you're doing would be:

SUBQUERY(toMany, $each, $each.name == %@ AND $each.value = %@)[EMAIL PROTECTED] > 0

Note that this is on the list of expensive predicate operations, so it should be towards the end of a compound predicate.

Cheers,
+Melissa



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to