tags:

views:

27

answers:

1

I have two entities: Folder <-->> Document, and Folder defines a To-Many relationship to Document with a cascade delete rule. My question is: is there some way for document object itself to detect when it is cascade deleted ?

+1  A: 

Your Document should receive a -[NSManagedObject validateForDelete:] message. You can also check whether an NSManagedObject is deleted (or scheduled for deletion) with -[NSManagedObject isDeleted]. So your Document's methods can perform the check on [self isDeleted].

Barry Wark
Thank you. I tried both of them. -[NSManagedObject validateForDelete:] is not I want. I want to check the delete status sometime later, not be notified during -[NSManagedObjectContext save:], and -[NSManagedObject validateForDelete:] will be called twice for each document, I don't know why. -[NSManagedObject isDeleted] did work if I delete Document directly, but If I delete Folder, -[document isDeleted] always return NO before and after -[NSManagedObjectContext save:]
gwang