I am creating an iOS 5 app using Core Data.
I have two entities Item and Category there is a many-to-many relationship between these two entities, i.e. an Item belongs to many categories and a Category has many items.
What I am trying to do is, given a category, I want to know all the categories the items of that category is associated with. For that I am trying to execute the following request:
NSEntityDescription *catEntity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = catEntity;
request.predicate = [NSPredicate predicateWithFormat:@"items IN %@",[category.items allObjects]];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
NSError *error = nil;
NSArray *categories = [context executeFetchRequest:request error:&error];
But when executing this I get the following error:
'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (items IN {<Item: 0x89b9c50> (entity: Item; id: 0x89be960 <x-coredata://A5DE0832-95F1-460C-9F40-202A10E16BDC/Item/p17> ; data: {
attributes = (
);
categories = (
"0x89be540 <x-coredata://A5DE0832-95F1-460C-9F40-202A10E16BDC/Category/p28>",
"0x89be680 <x-coredata://A5DE0832-95F1-460C-9F40-202A10E16BDC/Category/p29>"
);
name = "Some Item";
})})'
What am I doing wrong here?
Try this, I’m not sure but it might work: