Delete empty Core Data entities from to-many relationship
Delete empty Core Data entities from to-many relationship
- Subject: Delete empty Core Data entities from to-many relationship
- From: Steve Mills <email@hidden>
- Date: Fri, 13 Feb 2015 13:27:57 -0600
My model:
Folder:
attributes:
url
relationships:
Relationship: files, Destination: Asset, Inverse: folder, To Many, Deny
Relationship: keywords, Destination: Keyword, Inverse: assets, To Many, Nullify
Asset:
attributes:
stuff
relationships:
Relationship: folder, Destination: Folder, Inverse: files, To One, Nullify
Keyword:
attributes:
stuff
relationships:
Relationship: assets, Destination: Asset, Inverse: keywords, To Many, Nullify
When the last Asset that is a member of its Folder is deleted, I want to delete the now empty Folder. I added a prepareForDeletion override in Asset:
if(self.folder && self.folder.files.count == 1) {
Folder* fold = self.folder;
if([fold.files containsObject:self])
[self.managedObjectContext deleteObject:fold];
}
This works if I select one asset and delete it. But if I select multiple assets, it doesn't work. The count is never 1. It also spits out this:
2015-02-13 13:17:16.678 Image Chest[60293:9536015] Core Data: annotation: repairing missing delete propagation for to-many relationship files on object 0x6180000b1400 (0x618000030a60 <x-coredata:///Folder/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318160>) with bad fault 0x6180000cea80 (0x600000033e20 <x-coredata:///Asset/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318163>)
2015-02-13 13:17:16.678 Image Chest[60293:9536015] Core Data: annotation: repairing missing delete propagation for to-many relationship assets on object 0x6180000a7620 (0x600000420c40 <x-coredata:///Keyword/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318161>) with bad fault 0x6180000c57f0 (0x60000003abc0 <x-coredata:///Asset/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318162>)
2015-02-13 13:17:16.678 Image Chest[60293:9536015] Core Data: annotation: repairing missing delete propagation for to-many relationship assets on object 0x6180000a7620 (0x600000420c40 <x-coredata:///Keyword/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318161>) with bad fault 0x6180000cea80 (0x600000033e20 <x-coredata:///Asset/t3FB1E228-B84C-46CC-BB8C-C3FB8E002318163>)
Is there a better strategy for deleting empty container entities? At first I tried setting the Asset's folder relationship to Cascade, but that threw up all over.
--
Steve Mills
Drummer, Mac geek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden