Restkit:当外键指向Core Data中缺失的本地对象时,GET远程链接对象 [英] Restkit: GET remote linked object when foreign key refers to missing local object in Core Data

查看:150
本文介绍了Restkit:当外键指向Core Data中缺失的本地对象时,GET远程链接对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法确定Restkit是否能下载本地不存在的对象,特别是当外键在Core Data中以一对一的关系引用该对象时。

I cannot figure out if Restkit is able to download an object not present locally, in particular when a foreign key is referring to that missing object in a to-one relationship in Core Data.

采取以下示例:
- 联系人1指公司2

Take the following example: - contact 1 refers to company 2


  • 联系人1在用户检查联系人1的详细信息的UI中,然后执行针对联系人1的GET,则在本地db中存在公司2,但公司2不是

  • contact 1 is present in the local db but company 2 is not

GET返回一个包含其他联系人详细信息的JSON company_id = 2

the GET returns a JSON containing among other contact details the property company_id = 2

我已经通过外键关键字约定设置Restkit,其中我将外键存储在联系人对象(companyID)中,并将其链接到公司对象中存储的远程标识符(标识符):

I have already setup Restkit via the foreign key convention where I store the foreign key in the contact object (companyID) and I link it to the remote identifier (identifier) stored in the company object:

[contactResponseMapping addConnectionForRelationship:@forCustomerconnectedBy:@ {@companyID:@identifier}]

[contactResponseMapping addConnectionForRelationship:@"forCustomer" connectedBy:@{@"companyID" : @"identifier"}]

我不管理在这种情况下配置restkit下载实体(由company_id引用)如果不存在于本地db中。

I do not manage in this case to configure restkit to download the entity (referred to by the company_id) if not present in the local db.

这是可能的吗?

替代解决方法是覆盖companyID setter,并检查实体是否存在,如果没有下载实体,虽然这不是我想要的因为我已经设置了一个引擎,每当一个对象被编辑接收通知,并将其发布到服务器。这意味着我必须阻塞线程执行,直到下载链接的对象。

The alternative workaround would be to override the companyID setter and double check if the entity exists and if not download the entity, although this is not desirable to me as I have setup an engine that everytime that an object is edited receives a notification and post it to the server. This means I'd have to block the thread execution until the linked object is downloaded.

这个机制也称为延迟加载?或水合物?
我找不到任何其他类似的情况。

Also is this mechanism called lazy loading? or hydrating entities? I cannot find any other similar cases around.

希望你能帮助,对此有点疯狂。非常感谢。

Hope you can help, going a bit crazy on this. Thanks a lot.

PS:我使用restkit 0.21.0(即Blake Watters确认稳定的最新开发版本)

PS: I am using restkit 0.21.0 (i.e. the latest development release which Blake Watters confirmed to be stable)

推荐答案

这不是RestKit目前提供的功能(可能是因为您讨论的问题类型)。

This is not a feature that RestKit currently offers (probably because of the types of issues you discuss).

对于您的解决方法,考虑您的引擎与关系编辑相关的操作 - 它们如何推送回服务器?它们总是被推送吗?

For your workaround, consider what your engine is doing in relation to relationship edits - how are they pushed back to the server? Are they always pushed?

此外,考虑为你的外来对象创建存根对象,以便至少有一些表示总是存在(有几种方法这个,你可以设置映射来完成任务)。

Also, think about creating stub objects for your 'foreign' objects so that at least some representation always exists (there are a couple of ways to do this, you can setup mappings to accomplish the task). Then when you come to use one of these objects you can hydrate / lazy load it.

另请参阅澄清术语:水合实体:从数据库获取属性

这篇关于Restkit:当外键指向Core Data中缺失的本地对象时,GET远程链接对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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