Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magical Record deleting entity issue

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?

like image 282
Stas Avatar asked Aug 01 '13 17:08

Stas


1 Answers

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];
like image 88
Nenad M Avatar answered Oct 24 '22 07:10

Nenad M