title: Realm Migration - Changing Name of Class (for complex class)
body: <p>I'm not able to change the class name of a Realm Object that has properties pointing to other Realm Objects. A class like this, for example.</p>
  
  <pre><code>class OldClass: Object {
      var id: String!
      var dog: Dog!  //this is a Realm Object (with its own table)
  }
  </code></pre>
  
  <p>I've seen the simple examples of how to do this.</p>
  
  <pre><code>migration.enumerateObjects(ofType: "OldClass", { (oldObject, newObject) in
      migration.create("NewClass", value: oldObject!)
  })
  </code></pre>
  
  <p>I expect the above would work if the schemas for both OldClass and NewClass were the same, AND if all the properties were non-Realm objects. If the schemas are different, I've gathered that you can do something like this.</p>
  
  <pre><code>migration.enumerateObjects(ofType: "OldClass", { (oldObject, newObject) in
      let obj = migration.create("NewClass")
      obj["id"] = (oldObject["id"] as! String)
      obj["newPropertyName"] = (oldObject!["oldPropertyName"] as! Int)
  })
  </code></pre>
  
  <p>Neither of these example seem to work when your object has a property pointing to another Realm object though. At least this is what I suspect, since I get RLMException 'Can't create object with existing primary key value'. </p>
  
  <p>My suspicion is that the 'existing primary key' is referring to the Dog object, and that in migrating from NewClass to OldClass, the migration is trying to re-create the Dog object (which already exists).</p>
  
  <p>How do I properly perform this type of migration?</p>