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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -