Core Data NSPredicate for relationships.

Posted by Mugunth Kumar on Stack Overflow See other posts from Stack Overflow or by Mugunth Kumar
Published on 2009-05-29T15:15:52Z Indexed on 2010/04/18 10:13 UTC
Read the original article Hit count: 669

My object graph is simple.

I've a feedentry object that stores info about RSS feeds and a relationship called Tag that links to "TagValues" object. Both the relation (to and inverse) are to-many. i.e, a feed can have multiple tags and a tag can be associated to multiple feeds.

I referred to http://stackoverflow.com/questions/844162/how-to-do-core-data-queries-through-a-relationship and created a NSFetchRequest. But when fetch data, I get an exception stating,

NSInvalidArgumentException unimplemented SQL generation for predicate

What should I do? I'm a newbie to core data :( I know I've done something terribly wrong... Please help...

Thanks

--

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FeedEntry" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"authorname" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

NSEntityDescription *tagEntity = [NSEntityDescription entityForName:@"TagValues" inManagedObjectContext:self.managedObjectContext];
NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"tagName LIKE[c] 'nyt'"];          
NSFetchRequest *tagRequest = [[NSFetchRequest alloc] init];
[tagRequest setEntity:tagEntity];
[tagRequest setPredicate:tagPredicate];

NSError *error = nil;
NSArray* predicates = [self.managedObjectContext executeFetchRequest:tagRequest error:&error];


TagValues *tv = (TagValues*) [predicates objectAtIndex:0];
NSLog(tv.tagName); // it is nyt here...


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"tag IN %@", predicates];
[fetchRequest setPredicate:predicate];


// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController; 

--

© Stack Overflow or respective owner

Related posts about core-data

Related posts about iphone-sdk