NSPredicate that references multiple fields on a to-many relationship?

I'm using a SQLite persistent store. I have a NSManagedObject class Den with a to-many relationship Bear. Bear has several fields:

Bear:
    breed
    color
    age
    ...

When I am building fetch requests for my Den objects, I can filter to objects that have a related Bear with a certain field value:

NSPredicate *hasGrizzlyPred = [NSPredicate predicateWithFormat:@"ANY Bear.breed == 'grizzly'"];

Or I can just as easily search for a Den that has a brown bear:

NSPredicate *hasBrownBearPred = [NSPredicate predicateWithFormat:@"ANY Bear.color == 'brown'"];

But is there any way to search for a Den that has a bear that is both brown and a grizzly? The following is legal, but incorrect, I think:

// Not quite right: search for a den with a brown bear AND a grizzly
NSPredicate *hasBrownAndGrizzlyPred = [NSPredicate predicateWithFormat:@"ANY Bear.color == 'brown' AND ANY Bear.breed == 'grizzly'"];
6
задан Seamus Campbell 7 January 2011 в 18:12
поделиться