title: Android Realm copyToRealmOrUpdate creates duplicates of nested objects
body: <p>I have following classes:</p>
  
  <pre><code>public class Note extends RealmObject {
  
      @PrimaryKey
      private String id;
  
      private Template template;
  
      // other primitive fields, getters &amp; setters
  }
  
  public class Template extends RealmObject {
  
      private String name;
  
      private String color;
  
      // other primitive fields, getters &amp; setters
  }
  </code></pre>
  
  <p>I get my data from backend via Retrofit &amp; Gson, so I have ready-to-use java objects in response.</p>
  
  <p>Let's imagine that backend returns me same three Notes each time I call it.
  When I get the list of Note objects, I do the following:</p>
  
  <pre><code>private void fetchNotesAndSave() {
      List&lt;Notes&gt; notes = getNotesViaRetrofit();        
  
      Realm realm = Realm.getInstance(mContext);
      realm.beginTransaction();
      realm.copyToRealmOrUpdate(notes);
      realm.commitTransaction();
      realm.close();
  }
  </code></pre>
  
  <p>After that I call these lines to check count of stored objects:</p>
  
  <pre><code>int notesCount = mRealm.where(Note.class).findAll().size();
  int templatesCount = mRealm.where(Template.class).findAll().size();
  </code></pre>
  
  <p>For the first time:</p>
  
  <pre><code>notesCount == 3;
  templatesCount == 3;
  </code></pre>
  
  <p>That's right. But, if I call the server again, get same notes (same primaryKey ids), and call fetchNotesAndSave() again, I'll get these results:</p>
  
  <pre><code>notesCount == 3;
  templatesCount == 6;
  </code></pre>
  
  <p>Each time I call copyToRealmOrUpdate(), nested objects, that are inside of objects with primaryKey are duplicated - not updated.</p>
  
  <p>Is there any way to change this behaviour? 
  Please let me know if you need more information. Thanks in advance!</p>