核心数据 - 取消对象与关系的链接

发布于 2025-01-08 10:08:02 字数 609 浏览 0 评论 0原文

我在“Booking”对象和“Address”对象以及持久存储之间存在一对一的单向关系。

通常,每次预订都会使用相同的地址,并且在正常情况下这工作正常。

但是,如果由于某种原因在服务器端更改了预订地址,我想使用Address对象更新预订,并且从关系中删除现有的Address对象。这是因为我不希望更改原始 Address 对象 - 它应该保持在持久存储中的原样。

谁能告诉我这在核心数据中是否可行,以及如何去做?我目前正在使用 Magical Record Helper 库代码。

到目前为止,我的工作是在瞬态上下文中创建一个新的 Address 对象,取消链接到 Booking 的现有 Address 对象,然后将新的地址对象添加到预订。然而,在最后阶段会抛出错误。我也尝试过建立双向关系。

I have a one-to-one unidirectional relationship between a "Booking" object and an "Address" object and a persistent store.

Normally, each booking stays with the same Address, and under normal conditions this works fine.

However, if for some reason the booking address is changed on the server side, I want to update the Booking with a new Address object, and remove the existing Address object from the relationship. This is because I don't want the original Address object changed - that should stay as it is in the persistent store.

Can anyone tell me broadly whether this is possible in Core Data, and how to go about doing it? I'm currently using the Magical Record Helper library code.

My efforts so far have been to create a new Address object in a transient context, nullify the existing Address object linked to the Booking, and then add the new Address object to the Booking. However, an error is thrown at this last stage. I have also tried making the relationship bidirectional.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2025-01-15 10:08:02

我做错的是对新对象使用瞬态上下文,该对象及其被替换的关系位于默认上下文中。需要回到核心数据学校。

What I was doing wrong was using a transient context for the new object, which the object with its relationship being replaced was in the default context. Need to go back to core data school.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文