ios - deleting records that has recursive relationships in coredata -


i have below relationship in model. userstatement has levelupstatement , parentstatement has a-to 1 relationship between. problem have when try delete levelupstatement. have nullify both end of relationship , when try delete below: (mainuserstatement parentstatement)

self.mainuserstatementmodel.levelupstatement = nil; self.mainuserstatementmodel.levelupterm = nil; [[ashcoredatastack defaultstack].managedobjectcontext deleteobject:self.mainuserstatementmodel.levelupstatement];  error getting is:        terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-deleteobject: requires non-nil argument'.  

i know managedobjectcontext exists. problem should not there. how can safely delete levelupstatement without effecting levelupterm , parentstatement?

core data model

you need change order of lines of code:

[[ashcoredatastack defaultstack].managedobjectcontext deleteobject:self.mainuserstatementmodel.levelupstatement]; self.mainuserstatementmodel.levelupstatement = nil; self.mainuserstatementmodel.levelupterm = nil; 

in fact, if parentstatement relationship set 'nullify' not need second of these lines: coredata automatically nil out levelupstatement. check relationship in data model inspector:

enter image description here


Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -