Created
April 6, 2012 18:05
-
-
Save pnc/2321704 to your computer and use it in GitHub Desktop.
Fix to Marcus Zarra's consecutive migration code
This file contains 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
--- 1.txt 2012-04-06 14:09:33.000000000 -0400 | |
+++ 2.txt 2012-04-06 14:09:45.000000000 -0400 | |
@@ -119,28 +119,35 @@ | |
} | |
//END:progressivelyMigrateURLFindModels | |
//See if we can find a matching destination model | |
//START:progressivelyMigrateURLFindMap | |
NSMappingModel *mappingModel = nil; | |
NSManagedObjectModel *targetModel = nil; | |
NSString *modelPath = nil; | |
for (modelPath in modelPaths) { | |
targetModel = [[NSManagedObjectModel alloc] | |
- initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]]; | |
- mappingModel = [NSMappingModel mappingModelFromBundles:nil | |
- forSourceModel:sourceModel | |
- destinationModel:targetModel]; | |
- //If we found a mapping model then proceed | |
- if (mappingModel) break; | |
- //Release the target model and keep looking | |
- [targetModel release], targetModel = nil; | |
+ initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]]; | |
+ // We gain nothing by migrating to the same model | |
+ if ([targetModel isEqual:sourceModel] || | |
+ [[targetModel entityVersionHashesByName] isEqual:[sourceModel entityVersionHashesByName]]) { | |
+ // Ignore this model, it's the same one we're at and choosing it | |
+ // will lead to infinite recursion. | |
+ } else { | |
+ mappingModel = [NSMappingModel mappingModelFromBundles:nil | |
+ forSourceModel:sourceModel | |
+ destinationModel:targetModel]; | |
+ //If we found a mapping model then proceed | |
+ if (mappingModel) break; | |
+ //Release the target model and keep looking | |
+ [targetModel release], targetModel = nil; | |
+ } | |
} | |
//We have tested every model, if nil here we failed | |
if (!mappingModel) { | |
NSMutableDictionary *dict = [NSMutableDictionary dictionary]; | |
[dict setValue:@"No models found in bundle" | |
forKey:NSLocalizedDescriptionKey]; | |
*error = [NSError errorWithDomain:@"Zarra" | |
code:8001 | |
userInfo:dict]; | |
return NO; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment