Magical Record deleting entity issue

隐身守侯 提交于 2019-12-23 08:17:24

问题


I have a one-to-many relationship form Feedback to Questions in Feedback. The deletion rule is set to Nullify in Question and to Cascade in Feedback (so that when Feedback is deleted it deletes all its questions and when question is deleted it is pointer set to null in feedback.questions).

The problem is when I delete question (just a one question from many that exists in feedback) then I can't access feedback! Though the actual entry is really exist in DB (checked it with MesaSQLite) The code looks like:

FeedbackQuestion * questionToDelete = [FeedbackQuestion findByQuestionId:[entryID integerValue]];
DLog(@"Deleting FeedbackQuestion with ID: %@", questionToDelete.questionID);
success = [questionToDelete MR_deleteEntity];
//success is 1 here
***
// Accessing the feedback which question was deleted
Feedback * feedback = [Feedback findByFeedbackId:feedbackId];

feedback is null here. WHY? What am i doing wrong?


回答1:


Hm, try maybe the following line after your "//success is 1 here" comment line:

[[NSManagedObjectContext defaultContext] saveToPersistentStoreAndWait];

or, if you don't have the "shorthand-mode" enabled:

[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];


来源:https://stackoverflow.com/questions/18000640/magical-record-deleting-entity-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!