Core Data: migrating entities with self-referential properties
- by Dan
My Core Data model contains an entity, Shape, that has two self-referential relationships, which means four properties. One pair is a one-to-many relationship (Shape.containedBy <- Shape.contains) and the another is a many-to-many relationship (Shape.nextShapes <<- Shape.previousShapes). It all works perfectly in the application, so I don't think self-referencing relationships is a problem in general.
However, when it comes to migrating the model to a new version, then Xcode fails to compile the automatically generated mapping model, with this error message:
2009-10-30 17:10:09.387 mapc[18619:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "FUNCTION($manager ,'destinationInstancesForSourceRelationshipNamed:sourceInstances:' , 'contains' , $source.contains) == 1"'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff80d735a4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff83f0a313 objc_exception_throw + 45
2 Foundation 0x00007fff819bc8d4 _qfqp2_performParsing + 8412
3 Foundation 0x00007fff819ba79d +[NSPredicate predicateWithFormat:arguments:] + 59
4 Foundation 0x00007fff81a482ef +[NSExpression expressionWithFormat:arguments:] + 68
5 Foundation 0x00007fff81a48843 +[NSExpression expressionWithFormat:] + 155
6 XDBase 0x0000000100038e94 -[XDDevRelationshipMapping valueExpressionAsString] + 260
7 XDBase 0x000000010003ae5c -[XDMappingCompilerSupport generateCompileResultForMappingModel:] + 2828
8 XDBase 0x000000010003b135 -[XDMappingCompilerSupport compileSourcePath:options:] + 309
9 mapc 0x0000000100001a1c 0x0 + 4294973980
10 mapc 0x0000000100001794 0x0 + 4294973332
)
terminate called after throwing an instance of 'NSException'
Command /Developer/usr/bin/mapc failed with exit code 6
The 'contains' is the name of one of the self-referential properties. Anyway, the really big problem is that I can't even look at this Mapping Property as Xcode crashes as soon as I select the entity mapping when viewing the mapping model. So I'm a bit lost really where to go from here. I really can't remove the self-referential properties, so I'm thinking I've got manually create a mapping model that compiles? Any ideas?
Cheers