title: Using Mapping Models to migrate between Core Data Object Models
body: <p>I have a fairly simply schema. Essentially, Run &lt;--> Data (where a Run holds a data, e.g., Temperature, sampled from some sort of sensor). </p>
  
  <p>Now, it seems that sensors can have more than one measurement (e.g., Temperature and Humidity). So, a single Run could have multiple data samples.</p>
  
  <p>Hence, Run &lt;-->> Sample and Sample &lt;--> Data. (And for simplicity I am leaving Run &lt;--> Data in place, for now.)</p>
  
  <p>If I create a new mapping model, then things generally work - except that no new Samples are created, no relationships are established between Runs and Samples nor between Samples and Datas.</p>
  
  <p>I am trying to get mapping model to migrate my model but even the slightest change to the generated mapping model results in Cocoa error 134110. </p>
  
  <p>For example, if I take the "Sample" mapping (which has no Source) and set its Source to 'Run' (so that I can set Sample's inverse relationship 'run' appropriately) then the mapping changes its name to "RunToSample". There are two relationships handled in this mapping: data and run. The data property gets set automatically to </p>
  
  <p><code>FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:" , "DataToData", $source.dataSet)</code></p>
  
  <p>Following this example, I set the run property to</p>
  
  <p><code>FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:" , "RunToRun", $source)</code></p>
  
  <p>Similarly, I set the 'sample' property mapping in RunToRun to</p>
  
  <p><code>FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:" , "RunToSample", $source)</code></p>
  
  <p>and the 'sample' property in DataToData to</p>
  
  <p><code>FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:" , "RunToSample", $source.run)</code></p>
  
  <p>So, what, I wonder, is going wrong? I have tried various permutations, such as leaving the 'inverse' relationships unspecified. But I continue to get the same error (134110) regardless.</p>
  
  <p>I imagine that this is a lot easier than it seems and that I am missing some fundamental but minor piece. I have also tried subclassing NSEntityMigrationPolicy and overriding -createDestinationInstancesForSourceInstance: but these efforts have met with much the same results.</p>
  
  <p>Thanks in advance for any pointers or (relevant :-) advice.</p>
  
  <p>Edit: For simplicity, I have marked all relationships as optional. Though, ultimately, I may choose otherwise.</p>