Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSBatchDeleteRequest does not delete relationship

Tags:

ios

core-data

I have a problem with NSBatchDeleteRequest seems that is not possible to delete relationship references.

I have two entities:

  • News
  • Categories

where a category can have multiple news.

Now, when I try to delete all the objects in the core data using NSBatchDeleteRequest with the following code, then looking into the sqlite file seems that all categories are deleted, all news are deleted, but the relationship between categories and news persists, and this cause faults.

Here the delete function:

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:entityName];
NSBatchDeleteRequest *delete = [[NSBatchDeleteRequest alloc] initWithFetchRequest:fetchRequest];
[delete setResultType:NSBatchDeleteResultTypeCount];
NSError *error;
NSBatchDeleteResult *results = [deleteContext executeRequest:delete error:&error];

Any idea on how to fix this?

like image 691
Serluca Avatar asked Sep 28 '15 17:09

Serluca


People also ask

How to delete all Data in Coredata?

One approach to delete everything and reset Core Data is to destroy the persistent store. Deleting and re-creating the persistent store will delete all objects in Core Data.

How to delete Core Data Swift?

Table views have a built-in swipe to delete mechanic that we can draw upon to let users delete commits in our app. Helpfully, managed object context has a matching delete() method that will delete any object regardless of its type or location in the object graph.


1 Answers

You can probably do [manageObjectContext reset];

like image 190
Asadullah Ali Avatar answered Sep 28 '22 12:09

Asadullah Ali