TheLearner
TheLearner

Reputation: 19507

How to code complex Core Data Query using predicate

I am using Core Data however haven't done any complex queries and am completely lost - come from SQL background so need help creating a NSPredicate.

My question

I need to retrieve a list of Perspective's (with unique name) which in-directly belong to a specific EntityManagedObject.

Overview of the database

As you can see EntityManagedObject can have many EntityManagedObjects and can have many ObjectiveManagedObject's.

EntityManagedObject therefore has a single EntityManagedObject as a parent, and ObjectiveManagedObjective has a single EntityManagedObject as a parent.

ObjectiveManagedObject has one Perspective. A Perspective can belong to many ObjectiveManagedObjects.

enter image description here

Upvotes: 1

Views: 210

Answers (1)

waheeda
waheeda

Reputation: 1097

make a method,

-(NSArray *) getEntityManagedObjectsWithParentEntity:(EntityManagedObject *) parentObject;

another method,

-(NSArray *) getObjectiveManagedObjectsWithEntityManagedObjects:(NSArray *) entityManagedObjects;

then ,

-(NSArray *) getPerspectivesWithEntityManagedObject:(EntityManagedObject *) entityObject
{
   NSArray *objectiveManagedObjects = [self  getObjectiveManagedObjectsWithEntityManagedObjects: [self getEntityManagedObjectsWithParentEntity:entityObject] ];

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Objectives IN %@", objectiveManagedObjects];

}

Upvotes: 1

Related Questions