Im trying to do a search for a child entity based on a field “guid”. The guid field is defined in the parent entity. I would like to find the child instance whos guid is equal to some value i pass in but it always returns a result of 0 values. Im assuming core data isn’t seeing the guid property since its defined in the parent entity.
Here is my predicate:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:CHILD_ENTITY inManagedObjectContext:managedObjectContext]];
[request setPredicate:[NSPredicate predicateWithFormat:@"(guid like '%@')", guid]];
NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
if (results != nil && results.count > 0)
return YES;
else
return NO;
Is my predicate format wrong?
The solution is to use the full key path of the property.
That is, if parent is the name of the property which points to the logical parent you speak of.
Of course, if by parent you mean literal inheritance (i.e. [child isKindOfClass:[parent class]] is YES), than the issue may have simply been the quotes. I have assumed that you meant a logical parent which is a different instance, and has a relationship to the child (I guess it’s OOP terms VS ORM terms, or something like that).
Also, no need for parenthesis or quoted %@ in predicates this simple.