我在使用具有相同 toKeyPath (destinationKeyPath) 的多个 RKRelationshipMappings 时遇到问题。我已经成功地使用了一个 RKRelationshipMapping 到一个 toKeyPath,但我无法使用相同的 toKeyPath 附加第二个 RKRelationshipMappings。
具有一个有效的 RKRelationshipMapping 的代码:
RKObjectMapping *someObjectRequestMapping = [RKObjectMapping requestMapping];
[someObjectRequestMapping addAttributeMappingsFromDictionary:@{@"prop1" : @"prop_1", @"prop2" : @"prop_2"}];
RKObjectMapping *firstSubObjectMapping = [RKObjectMapping requestMapping];
[firstSubObjectMapping addAttributeMappingsFromDictionary:@{@"subProp1" : @"sub_prop1", @"subProp2" : @"sub_prop2"}];
[someObjectRequestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"prop3"
toKeyPath:@"prop_3"
withMapping:firstSubObjectMapping];
但是,如果我想使用相同的 toKeyPath(“prop_3”)将另一个 RKRelationshipMapping 添加到“someObjectRequestMapping”,则 RestKit 失败并出现错误:
*'NSInternalInconsistencyException',原因:'无法为 keyPath 邀请属性添加映射,一个已经存在...'*
带有两个失败的 RKRelationshipMappings 的代码:
RKObjectMapping *someObjectRequestMapping = [RKObjectMapping requestMapping];
[someObjectRequestMapping addAttributeMappingsFromDictionary:@{@"prop1" : @"prop_1", @"prop2" : @"prop_2"}];
RKObjectMapping *firstSubObjectMapping = [RKObjectMapping requestMapping];
[firstSubObjectMapping addAttributeMappingsFromDictionary:@{@"subProp1" : @"sub_prop1", @"subProp2" : @"sub_prop2"}];
RKObjectMapping *secondSubObjectMapping = [RKObjectMapping requestMapping];
[secondSubObjectMapping addAttributeMappingsFromDictionary:@{@"subProp2" : @"sub_prop2", @"subProp3" : @"sub_prop3"}];
[someObjectRequestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"prop3"
toKeyPath:@"prop_3"
withMapping:firstSubObjectMapping];
[someObjectRequestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"prop4"
toKeyPath:@"prop_3"
withMapping:secondSubObjectMapping];
该映射用于 RKRequestDescriptor。
任何帮助将不胜感激。
最好的祝福,
达米尔