Update to the question below: We were able to query the child entity using the Father entity fetch request by using fatherChild relationship. Sample query is as follows:
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"fatherChild.name LIKE 'fx'"];
Now what we are trying to do is to use the predicate above but another another condition where we want to find child for a given fathers name. We used the following code
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"name LIKE 'john' AND ANY fatherChild.name in 'fx'"];
But the program crashed with the exception: [__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xad49c40
Reading through examples we see we can use subquery but not sure what the syntax would be for our case where we have a entity with one to many relationship. Any help would be appreciated?
Thanks.
Question: We have a data model with three entities: Father, Mother and Child. Please see the image for reference.
An example Query request we have on the father entity is given below :
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Father"
inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSString *attributeName = @"name";
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"%K like %@",
attributeName, searchField.text];
We have similar query request for Mother and Child entities. What we would like to do is to create one query to combine Father and Mother entities. For example we want to search on Father's name =Mike and Mothers name =Jen in a single query. How do we do it?
Thanks for your response.