2013-07-04 27 views
1

的,我有以下型號:如何刷新(無瞬態)與對象基於_id關係獲取不同步

@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通話完成。由於我製造商ID非瞬態,我仍然會存儲它。我如何更新關係呢?

一種可能性是一旦製造商取回,就取回模型。但是,我有其他更復雜的對象,這種方法不會工作,並且效率不高。如何根據該ID鏈接CoreData中的關係?

非常感謝!

回答

0

您的建議解決方案是正確的,您只需選擇如何預測您的提取,以便只返回未連接的模型。如果有大量項目要處理,您還可以批量提取,更新和保存。在這種情況下,沒有辦法讓Core Data或RestKit爲您建立關係。

相關問題