0

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

westsider
  • 4,967
  • 5
  • 36
  • 51
Daniel Thorpe
  • 3,911
  • 2
  • 28
  • 28
  • When you say "migrating the model to a new version" is that a new version of the app, Xcode, OS? – TechZen Oct 30 '09 at 19:51
  • I believe that he's trying to create the automatic migration mapping to a new CoreData model schema -- in creating a newer version of his app, he's changed the schema, and wants to have the newer app migrate the old data to the new schema. I think. – mbauman Oct 30 '09 at 21:49
  • Yeah, that's exactly right. I've updated my Core Data schema and I don't want to lose the contents of my datastore, so I need to migrate the current datastore to a new version of my schema. I'm starting to think that this is actually a bug in Xcode, specially in the decoding/compiling of the model mapping file with reflexive relationships which generate some sort of infinite loop... I'm going to ask on cocoa-dev, will post back here if I get a response over there. – Daniel Thorpe Nov 02 '09 at 11:00

1 Answers1

6

Okay, so it seems as though "contains" might be a reserved word, and as such needs to be escaped using a "#". The Apple docs on migration don't specifically mentions it as a reserved word, although they also don't say what the definitive list is.

But, it seems that a property name cannot be the same as any NSObject or NSManagedObject method name, such as "description", and apparently "contains".

Daniel Thorpe
  • 3,911
  • 2
  • 28
  • 28