Code Data: Re-inserting deleted objects
Code Data: Re-inserting deleted objects
- Subject: Code Data: Re-inserting deleted objects
- From: chaitanya pandit <email@hidden>
- Date: Fri, 3 Oct 2008 03:02:51 +0530
Hi List,
What is the best way to re-insert a deleted object back in to the
managed object context?
At present i'm trying to this:
if ([objectToReinstate validateForInsert:&error])
[[self managedObjectContext] insertObject:objectToReinstate];
But i am having problems with objects having relationships, suppose i
have entities A,B and C having relationships as: A<--->B<--->C
All the relationships are mandatory (i.e the optional flag is
unchecked) also the delete rule for A--->B and B--->C is Cascade .
Now suppose i delete A, due to the cascade rule B and C will also get
deleted. Now if i want to reinsert all of them in to the MOC, i kinda
have a deadlock situation
If i do this:
if ([A validateForInsert:&error])
[[self managedObjectContext] A];
It will not work because to reinsert A needs a valid relationship with
B which in this case will be nil.
i cannot re insert B either because i haven't inserted A and so on.
One more thing, if i directly insert the object without checking it
for validation and then call [A isInserted] it returns NO if i do it
in the same loop, if i do it later, it returns YES, is there anything
special i need to do so that the isInserted flag would be updated?
I' appreciate any help.
thanks,
Chaitanya
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden