• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Delete empty Core Data entities from to-many relationship
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Delete empty Core Data entities from to-many relationship
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: Question for StackOverflow or other about not sharing cookie jar per webview
  • Next by Date: WKWebView + <input type="file">
  • Previous by thread: Re: All buttons lost focus ring on Yosemite
  • Next by thread: Re: Delete empty Core Data entities from to-many relationship
  • Index(es):
    • Date
    • Thread