我需要创建一个实体与同一实体的关系。基本上它是Meetings
实体,可能有ParantMeeting
。
这就是我创造关系的方式。
- (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]];
它创建了一个无限循环。是否有任何其他方式可以创建与同一实体的关系。
请帮忙。
答案 0 :(得分:6)
替换导致递归的行:
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];
直接引用映射本身:
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:meetingsMapping];