Restkit嵌套数组映射错误

时间:2013-02-07 13:19:37

标签: mapping restkit relationships multidimensional-array

我正在尝试映射以下结构:

Plan.json:

{
  "id" : "1",
  "floors" : [
    {
      "floor" : "1",
      "constrains" : 
      {
        "southWest":
        {
          "latitude": 50.076534 ,
          "longitude": 14.417152
        },
        "northEast":
        {
          "latitude": 50.077194,
          "longitude": 14.418526
        }
      }

    }
  ]
}

对于这种结构:

@interface Plan : NSManagedObject

@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Building *building;
@property (nonatomic, retain) NSSet *floors;
@end

@interface Floor : NSManagedObject
@property (nonatomic, retain) NSNumber * floorId;
@property (nonatomic, retain) NSNumber * planId;
@property (nonatomic, retain) NSNumber * southWestLatitude;
@property (nonatomic, retain) NSNumber * southWestLongitude;
@property (nonatomic, retain) NSNumber * northEastLatitude;
@property (nonatomic, retain) NSNumber * northEastLongitude;
@property (nonatomic, retain) Plan *plan;
@end

映射:

RKEntityMapping *floorMapping = [RKEntityMapping mappingForEntityForName:@"Floor" inManagedObjectStore:managedObjectStore];


floorMapping.identificationAttributes = @[ @"floorId" ];
[floorMapping addAttributeMappingsFromDictionary:@{
 @"floor": @"floorId",
 @"constraints.southWest.latitude": @"southWestLatitude",
 @"constraints.southWest.longitude": @"southWestLongitude",
 @"constraints.northEast.latitude": @"northEastLatitude",
 @"constraints.northEast.longitude": @"northEastLongitude"
 }];


RKEntityMapping *planMapping = [RKEntityMapping mappingForEntityForName:@"Plan" inManagedObjectStore:managedObjectStore];


planMapping.identificationAttributes = @[ @"id" ];
[planMapping addAttributeMappingsFromDictionary:@{
 @"id": @"id"}];



[planMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"floors" toKeyPath:@"floors" withMapping:floorMapping]];

我认为我做的一切都是正确的,它实际上是来自TwitterCoreData的例子。但我仍然得到了这样的答复: 对于计划

<Plan: 0x7385ca0> (entity: Plan; id: 0x736fdf0 <x-coredata://C74D92C0-FF0D-49F4-807B-F8B431733B8A/Plan/p1> ; data: {
    floors = "<relationship fault: 0x7386ac0 'floors'>";
    id = 1;
})

对于地板

2013-02-07 14:39:55.184 CVUT Navigator[18061:c07] (
    "<Floor: 0x9353130> (entity: Floor; id: 0x933d670 <x-coredata://C74D92C0-FF0D-49F4-807B-F8B431733B8A/Floor/p1> ; data: <fault>)"
)

没有抛出错误,只是错误的数据。你知道怎么办吗?

谢谢 托马斯

0 个答案:

没有答案