我有以下模型:
@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 。由于我将制造商 ID 设为非瞬态,因此我仍将其存储。那我该如何更新关系呢?
一种可能性是在获取制造商后获取模型。但是,我还有其他更复杂的对象,这种方法不起作用且效率不高。如何根据该 ID 链接 CoreData 中的关系?!
非常感谢!