CoreData: “Dangling reference to an invalid object.” error

后端 未结 9 2137
余生分开走
余生分开走 2021-01-01 11:44

I\'m working on a Cocoa-Touch app, it uses CoreData and has some NSPersistentObject subclasses generated by the XCode model editor.

I\'ve noticed that recently, when

9条回答
  •  忘掉有多难
    2021-01-01 12:50

    Let's say you have a table "recipes" and a child table "ingredients". You then create a one-to-many relation from recipe's to ingredients and also create an inverse relationship (one-to-one) from ingredients to recipes. It makes sense to specify a delete rule of "cascade" from the recipes table because if you delete a recipe the ingredient should also be deleted. However, if you specify "no action" in the delete rule on the one-to-one relationship in ingredients you will get the dangling reference error when you try to delete an ingredient. Change the delete rule on the one-to-one relationship to "nullify" and this should correct the problem.

提交回复
热议问题