Created
December 18, 2011 20:01
-
-
Save raheelahmad/1494298 to your computer and use it in GitHub Desktop.
Intense Core Data migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL) createRelationshipsForDestinationInstance:(NSManagedObject *) destinationAttendance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { | |
NSArray *sourceAttendances = [manager sourceInstancesForEntityMappingNamed:[mapping name] | |
destinationInstances:[NSArray arrayWithObject:destinationAttendance]]; | |
NSManagedObject *sourceAttendance = [sourceAttendances objectAtIndex:0]; | |
NSArray *allStudents = [[[sourceAttendance valueForKey:@"theSchedule"] valueForKey:@"theCourse"] valueForKey:@"students"]; | |
NSArray *presentStudents = [sourceAttendance valueForKey:@"students"]; | |
NSLog(@"For attendance on %@", [sourceAttendance valueForKey:@"date"]); | |
for (NSManagedObject *a_student in allStudents) { | |
NSManagedObject *destination_student = [[manager destinationInstancesForEntityMappingNamed:@"StudentToStudent" | |
sourceInstances:[NSArray arrayWithObject:a_student]] | |
objectAtIndex:0]; | |
NSManagedObject *presence = [NSEntityDescription insertNewObjectForEntityForName:@"Presence" | |
inManagedObjectContext:[manager destinationContext]]; | |
if ([presentStudents containsObject:a_student]) { | |
[presence setValue:[NSNumber numberWithBool:YES] forKey:@"present"]; | |
NSLog(@"Created a present for %@ %@", [a_student valueForKey:@"firstName"], [a_student valueForKey:@"lastName"]); | |
} | |
else { | |
[presence setValue:[NSNumber numberWithBool:NO] forKey:@"present"]; | |
NSLog(@"Created an absence for %@ %@", [a_student valueForKey:@"firstName"], [a_student valueForKey:@"lastName"]); | |
} | |
[presence setValue:destination_student forKey:@"student"]; | |
[presence setValue:destinationAttendance forKey:@"attendance"]; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment