Skip to content
Browse files

Method to delete all entities in a specified context matching a given…

… predicate
  • Loading branch information...
1 parent 524a874 commit 2605f17ca38b21b03b481f6a86ea8dd7ea86a44c @myell0w myell0w committed Oct 14, 2011
View
1 activerecord-coredata/NSManagedObject+ActiveRecord.h
@@ -32,6 +32,7 @@
+ (BOOL) truncateAll;
+ (BOOL) truncateAllMatchingPredicate:(NSPredicate *)searchTerm;
+ (BOOL) truncateAllInContext:(NSManagedObjectContext *)context;
++ (BOOL) truncateAllMatchingPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;
+ (NSArray *) ascendingSortDescriptors:(id)attributesToSortBy, ...;
+ (NSArray *) descendingSortDescriptors:(id)attributesToSortyBy, ...;
View
15 activerecord-coredata/NSManagedObject+ActiveRecord.m
@@ -700,20 +700,23 @@ + (BOOL) truncateAllInContext:(NSManagedObjectContext *)context
return YES;
}
-+ (BOOL) truncateAllMatchingPredicate:(NSPredicate *)searchTerm
-{
- NSFetchRequest *request = [self requestAll];
++ (BOOL) truncateAllMatchingPredicate:(NSPredicate *)searchTerm {
+ return [self truncateAllMatchingPredicate:searchTerm inContext:[NSManagedObjectContext contextForCurrentThread]];
+}
+
++ (BOOL) truncateAllMatchingPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context {
+ NSFetchRequest *request = [self requestAllInContext:context];
[request setPredicate:searchTerm];
[request setIncludesSubentities:NO];
[request setIncludesPropertyValues:NO];
[request setFetchBatchSize:[self defaultBatchSize]];
-
+
NSArray *objectsToTruncate = [self executeFetchRequest:request];
-
+
for (id objectToTruncate in objectsToTruncate) {
[objectToTruncate deleteEntity];
}
-
+
return YES;
}

0 comments on commit 2605f17

Please sign in to comment.
Something went wrong with that request. Please try again.