RestKit - 关系映射到同一实体会创建无限循环

时间:2014-03-31 06:12:50

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

我需要创建一个实体与同一实体的关系。基本上它是Meetings实体,可能有ParantMeeting

enter image description here

这就是我创造关系的方式。

- (RKEntityMapping *)meetingsMapping {

    RKEntityMapping *meetingsMapping = [RKEntityMapping mappingForEntityForName:@"DBMeetings" inManagedObjectStore:objectManager.managedObjectStore];
    meetingsMapping.setDefaultValueForMissingAttributes = NO;
    meetingsMapping.deletionPredicate = [NSPredicate predicateWithFormat:@"shouldBeDeleted = 1"];
    [meetingsMapping setModificationAttributeForName:@"updated_at"];
    meetingsMapping.identificationAttributes = @[@"id"];

    [meetingsMapping addAttributeMappingsFromDictionary:@{
                                                          @"id": @"id",
                                                          @"title": @"title",

                                                          @"start_time": @"start_time",
                                                          @"finish_time": @"finish_time",

                                                          @"lock": @"lock",
                                                          @"location": @"location",
                                                          @"sample": @"sample",

                                                          @"deleted": @"shouldBeDeleted",

                                                          @"created_at": @"created_at",
                                                          @"updated_at": @"updated_at",
                                                          @"follow_up_id": @"follow_up_id",
                                                          @"total_topics": @"total_topics",
                                                          }];

    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"tags" mapping:[self tagsMapping]];
    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"required_participants" mapping:[self contactsMapping]];
    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"optional_participants" mapping:[self contactsMapping]];
    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"readonly_participants" mapping:[self contactsMapping]];
    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"organizer" mapping:[self contactsMapping]];
    [meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];

    return meetingsMapping;
}

每当我为parent_meeting

添加关系映射时
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];

它创建了一个无限循环。是否有任何其他方式可以创建与同一实体的关系。

请帮忙。

1 个答案:

答案 0 :(得分:6)

替换导致递归的行:

[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];

直接引用映射本身:

[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:meetingsMapping];