Doing a NSFetchRequest on a single NSManagedObject
Doing a NSFetchRequest on a single NSManagedObject
- Subject: Doing a NSFetchRequest on a single NSManagedObject
- From: Andrew Sage <email@hidden>
- Date: Sat, 6 Aug 2005 16:48:19 +0100
My data model consists of an Entity called Project which has a one to
many relationship to
an Entity called Task. Task has an attribute called completedDate.
I am wanting to get the number of Tasks that do not have a
completedDate set.
Project is represented by a class called Project.
I have created the following method in Project:
-(int)tasksCount
{
int total = 0;
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Task"
inManagedObjectContext:moc];
NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"completedDate =
NIL"];
NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
[fetch setEntity: entity];
[fetch setPredicate: predicate];
NSArray * results = [moc executeFetchRequest:fetch error:nil];
[fetch release];
total = [results count];
return total;
}
However, this returns the number of Tasks that do not have a
completedDate set for all the Projects
and not just the current one.
Thanks.
Andrew
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden