开发者

Does core data delete objects with cascading delete rules instantly or on-save?

In a Core Data model, entity A has a relation to entity B with the delete rule set to Cascade. Is object B immediately deleted when the [context deleteObject:A] is called, or does Core Data wait for the [context save:&error] method, like it does wit开发者_StackOverflowh object validation?

I'm wondering if after deleting A, I could create an object C that would then search for B in the context and establish the relation. Would that prevent B from being deleted?

Cheers, Eric-Paul.


"Deleted" is merely a state. How that state is persisted when the user (or your app) saves is an implementation detail. It can still be undone after a save if the file hasn't been closed and its state lost.

If your intention is to move the B instances of an A instance to another instance of A, you need to change the relationship before you delete the first A instance, else the cascade rule will take the Bs with it (per the exact definition of the rule's behavior). Once deleted (whether directly or by a cascade rule), it's deleted. Searches won't reveal deleted Bs.

So: if you want to preserve an A's Bs, assign the Bs to another A before deleting the original. Otherwise, you'll need to create new Bs for the new A.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜