Reputation: 9241
I need to create relationship of an entity to the same entity. Basically it is Meetings
entity that may have any ParantMeeting
.
This is how I am creating relationship.
- (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;
}
And whenever I add relationship mapping for parent_meeting
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];
It creates an infinite loop. Is there any other way of creating relationship to same entity.
Please help.
Upvotes: 2
Views: 338
Reputation: 119031
Replace the line that causes the recursion:
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:[self meetingsMapping]];
with a direct reference to the mapping itself:
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"parent_meeting" mapping:meetingsMapping];
Upvotes: 6