{"id":13678,"date":"2016-02-25T11:01:50","date_gmt":"2016-02-25T16:01:50","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13678"},"modified":"2016-02-25T11:22:34","modified_gmt":"2016-02-25T16:22:34","slug":"core-data-join-table-records-not-deleted-in-ordered-relationship","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/02\/25\/core-data-join-table-records-not-deleted-in-ordered-relationship\/","title":{"rendered":"Core Data Join Table Records Not Deleted in Ordered Relationship"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/questions\/34137942\/core-data-join-table-records-not-deleted-in-many-to-many-relationship\/34144680#34144680\">Tonester<\/a>:<\/p>\n<blockquote cite=\"http:\/\/stackoverflow.com\/questions\/34137942\/core-data-join-table-records-not-deleted-in-many-to-many-relationship\/34144680#34144680\"><p>I&rsquo;m having trouble with a core data many-to-many relationship where both side&rsquo;s delete rules are set to Nullify. I&rsquo;m finding when I inspect the SQL database there are records left in the join table that should be deleted.<\/p><p>The two tables represent Playlists and Tracks. Playlist deletes don&rsquo;t cascade to delete each track automatically because each track can be in multiple playlists.<\/p><\/blockquote>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/34137942\/core-data-join-table-records-not-deleted-in-many-to-many-relationship\/34144680#comment56056801_34144680\">Tonester<\/a>:<\/p>\n<blockquote cite=\"http:\/\/stackoverflow.com\/questions\/34137942\/core-data-join-table-records-not-deleted-in-many-to-many-relationship\/34144680#comment56056801_34144680\"><p>I&rsquo;ve noticed if you delete the relationship i.e. using removePlaylistTracksObject:, then save, then delete the playlist and track, then save, it works. I would expect the relationship record to be removed when deleting either the playlist or track and a single save. Also if the playlist to tracks is not ordered it works fine.<\/p><\/blockquote>\n<p><a href=\"http:\/\/stackoverflow.com\/a\/34144680\/6311\">Marcus Zarra<\/a>:<\/p>\n<blockquote cite=\"http:\/\/stackoverflow.com\/a\/34144680\/6311\"><p>Thanks for the test case, that is an actual issue in Core Data. There is nothing in there that you are doing incorrectly. You <em>really<\/em> need to file a radar on this and I will file one as well.<\/p>\n<p>In the interim you can either stop using ordered relationships (they are a bastardization anyway) or do the double delete.<\/p><\/blockquote>\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2015\/06\/18\/core-data-bugs\/\">Core Data Bugs<\/a>.<\/p>\n<p>Update (2016-02-25): <a href=\"https:\/\/twitter.com\/jpohh\/status\/702888617337749504\">James O&rsquo;Leary<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/jpohh\/status\/702888617337749504\"><p>Every year for (x) years I think &ldquo;I should get rid of my ordering hack&rdquo;, do research, and find CD&rsquo;s is still broken :(<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Tonester: I&rsquo;m having trouble with a core data many-to-many relationship where both side&rsquo;s delete rules are set to Nullify. I&rsquo;m finding when I inspect the SQL database there are records left in the join table that should be deleted.The two tables represent Playlists and Tracks. Playlist deletes don&rsquo;t cascade to delete each track automatically because [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[131,109,31,1137,30,1199,71],"class_list":["post-13678","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-coredata","tag-ios","tag-ios-9","tag-mac","tag-mac-os-x-10-11","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=13678"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13678\/revisions"}],"predecessor-version":[{"id":13688,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13678\/revisions\/13688"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}