-setPropagatesDeletesAtEndOfEvent:实际上是做什么的? [英] What does -setPropagatesDeletesAtEndOfEvent: actually do?

查看:74
本文介绍了-setPropagatesDeletesAtEndOfEvent:实际上是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我尝试一下:如果我未设置此项,则默认值为YES。因此,当我从上下文中删除托管对象时,上下文会立即将此对象传播到持久性存储中,从而使对象消失了。



然后将其设置为NO时,仅在调用-save时才从持久性存储中删除对象?



这是真的吗?我的意思是:如果为true,则默认行为是一旦调用上下文删除对象,该对象就消失了。假设您没有使用撤消管理器。所以...走了。对?无法回滚吗?还是仍然可以通过回滚来恢复它? didChange ... 方法调用(显式或合成的)。



据我所知,这仅会影响标记内存中的对象将其标记为要删除还是不删除。它仅影响上下文如何管理内存中的对象,而不影响上下文在磁盘删除时的管理方式。设置为YES时,它将导致上下文将对象标记为要删除的对象,并将其视为从对象图中删除。但是,撤消操作将反转该标志,就像您直接删除该对象一样。



该标志可用是因为有时甚至在删除或级联关系结束后,有时您仍然需要对象闲逛一会儿。当为否时,上下文将返回已删除的对象,直到下一次保存为止。



这是一项高级功能,很少使用。


Let me try it: If I don't set this, then the default value is YES. So when I delete an managed object from the context, the context propagates this immediately to the persistent store so the object is gone?

And when I set this to NO, then objects are deleted from the persistent store only when calling -save?

Is that really true? I mean: If it was true, then the default behavior is that once you call the context to delete an object, the object is gone. Lets assume you're not using an undo manager. So... gone. Right? No rollback possible? Or can it still be recovered with a rollback?

解决方案

This controls whether deletes are propagated at the time of a change event i.e. following a didChange... method call (explicit or synthesized.)

To my knowledge this only affects the flags on objects in memory marking them as to be deleted or not. It only affects how the context manages the in-memory objects and not how the context manages on disk deletions. When set to YES, it cause the context to flag the objects as one to be deleted and treat it as removed from the object graph. However, an undo will reverse the flag just as if you had directly deleted the object.

This flag is available because there maybe times when when you need objects to hang around for a while even after a delete or cascade relationship has ended. When NO the context will return the "deleted" object up to the point of the next save.

This is an advanced feature and it is seldom used.

这篇关于-setPropagatesDeletesAtEndOfEvent:实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆