使用 StackMob 作为后端。我有一个Event
实体,它的关系称为 user users
(type NSSet
)。现在我想获取某个用户的所有username
事件@"someuser"
。我的代码是这样的:
[self.client getLoggedInUserOnSuccess:^(NSDictionary *result) {
NSString *currentlyLoggedInUser = [result valueForKey:@"username"];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *eventEntity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedOjbectContext];
[request setEntity:eventEntity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY users.username = %@", currentlyLoggedInUser];
NSLog(@"predicate: %@", predicate);
[request setPredicate:predicate];
NSLog(@"request: %@", request);
events = [NSArray new];
events = [self.managedOjbectContext executeFetchRequest:request error:nil];
/* this is working...
for (Event *e in events) {
NSLog(@"%@",[e.users filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"username == %@", currentlyLoggedInUser]]);
}
*/
NSLog(@"events: %@", events);
} onFailure:^(NSError *error) {
}];