Magical Record删除实体问题 [英] Magical Record deleting entity issue

查看:208
本文介绍了Magical Record删除实体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对多的关系形式反馈给反馈中的问题。删除规则设置为Nullify问题和反馈级联(因此,当反馈被删除时,它删除所有问题,并且当问题被删除时,它的指针在反馈请求中设置为null)。

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).

问题是当我删除问题(只是一个问题从许多反馈存在),然后我不能访问反馈!虽然实际的条目真的存在于DB(用MesaSQLite检查)
代码如下:

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];

反馈为空。为什么?

推荐答案

您可以在// success is 1 here注释行之后尝试以下行:

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];

这篇关于Magical Record删除实体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆