re: Code Data: Re-inserting deleted objects
Chaitanya, What is the best way to re-insert a deleted object back in to the managed object context? -insertObject: will reinsert a deleted object. -insertObject and - deleteObject will cancel each other out. Typically, one wouldn't validateForInsert until after reinserting the object, and then fixing up the relationships. -validateForInsert is closer in meaning to "can I save (insert into db) this object yet ?" It's perfectly fine to be in an in between state, as long as you clean it up before saving. 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? If insertObject & deleteObject cancel each other out, then -isInsert will return NO, since the deletion was effectively canceled, and you won't be saving either the insert or delete to the database. Basically, you returned to a neutral state. - Ben ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Code Data: Re-inserting deleted objects
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]