如何根据_id(无瞬态)刷新与不同步的对象的关系

时间:2013-07-04 21:19:27

标签: objective-c rest core-data restkit restkit-0.20

我有以下型号:

@interface EquipmentModel : NSManagedObject

@property (nonatomic, retain) NSDate * creationDate;
@property (nonatomic, retain) NSString * desc;
@property (nonatomic, retain) NSNumber * identifier;
@property (nonatomic, retain) NSDate * lastModifiedDate;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * manufacturerID;
@property (nonatomic, retain) Manufacturer *manufacturer;

我使用RESTKit和以下映射获取该对象:

RKEntityMapping *equipmentModelMapping = [RKEntityMapping mappingForEntityForName:@"EquipmentModel" inManagedObjectStore:managedObjectStore];
equipmentModelMapping.identificationAttributes = @[@"identifier"];
[equipmentModelMapping addAttributeMappingsFromDictionary:@{
 @"id": @"identifier",
 @"description": @"desc",
 @"manufacturer_id": @"manufacturerID",
 @"creation_date": @"creationDate",
 @"last_modified_date": @"lastModifiedDate",
 }];
[equipmentModelMapping addAttributeMappingsFromArray:@[ @"name"]];
[equipmentModelMapping addConnectionForRelationship:@"manufacturer" connectedBy:@{ @"manufacturerID": @"identifier"}];

然而,有时制造商不会在模型之前获取,因此一旦 getObjectsAtPath ,模型的关系“制造商”关系将等于nil strong>通话已完成。由于我将manufacturerID设为非瞬态,我仍然会将它存储起来。我怎样才能更新关系呢?

一种可能性是在获取制造商后获取模型。但是,我有其他更复杂的对象,这种方法不起作用,效率不高。如何根据该ID链接CoreData中的关系?!

非常感谢!

1 个答案:

答案 0 :(得分:0)

您建议的解决方案是正确的,您只想选择如何预测您的提取,以便仅返回未连接的模型。如果要处理大量项目,您还可以批量提取,更新和保存。在这种情况下,没有办法让Core Data或RestKit为您建立关系。