FROM : Chris Hanson
DATE : Fri Feb 01 21:36:37 2008
On Feb 1, 2008, at 12:03 PM, Carter R. Harrison wrote:
> Today I'm working with NSFetchRequests for the first time and I need
> some help learning how to filter down the initial set of managed
> objects that I want to search against.
> Entity: File
> Relationship: Messages
I assume you actually mean "messages" given that properties of objects
in Objective-C start with lower-case letters. :)
> My initial thought was to add more criteria to my predicate to help
> narrow down the search base, but I'm not sure how the predicate's
> criteria could traverse relationships.
Magic. :)
Do all of your relationships have appropriate inverses? If not, they
should. Then you could just use a predicate like this:
NSPredicate *fieldSearchPredicate = [NSPredicate predicateWithFormat:
@"(message.file IN %@) AND (value = %@)", files,
requestedFieldValue];
Use that in a fetch request on the Field entity and it should just
work. "files" should be an NSArray or NSSet of instances of your File
entity, or NSManagedObjectID instances representing instances of your
File entity.
-- Chris
DATE : Fri Feb 01 21:36:37 2008
On Feb 1, 2008, at 12:03 PM, Carter R. Harrison wrote:
> Today I'm working with NSFetchRequests for the first time and I need
> some help learning how to filter down the initial set of managed
> objects that I want to search against.
> Entity: File
> Relationship: Messages
I assume you actually mean "messages" given that properties of objects
in Objective-C start with lower-case letters. :)
> My initial thought was to add more criteria to my predicate to help
> narrow down the search base, but I'm not sure how the predicate's
> criteria could traverse relationships.
Magic. :)
Do all of your relationships have appropriate inverses? If not, they
should. Then you could just use a predicate like this:
NSPredicate *fieldSearchPredicate = [NSPredicate predicateWithFormat:
@"(message.file IN %@) AND (value = %@)", files,
requestedFieldValue];
Use that in a fetch request on the Field entity and it should just
work. "files" should be an NSArray or NSSet of instances of your File
entity, or NSManagedObjectID instances representing instances of your
File entity.
-- Chris
| Related mails | Author | Date |
|---|---|---|
| Carter R. Harrison | Feb 1, 21:03 | |
| Chris Hanson | Feb 1, 21:36 | |
| Carter R. Harrison | Feb 1, 21:41 |






Cocoa mail archive

