title: Realm: updating objects with the same primary keys in an array
body: <p>I have an Invoice array that includes objects from Products array and I'm trying to update each Invoice array object independently, but when I update one object's property, all other objects' properties change.</p>
  
  <p>For instance, In my first invoice I add 2 pens to the list, then in the second invoice, I add one pen, but after adding the second invoice, the count property of the first invoice also changes to 1.</p>
  
  <p>How can I update one of them without affecting the other?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// First Invoice
  [
    {"date":0,"id":1,"products":
      [
        {"count":"2","format":"","id":"6921738073439","name":"pen","price":"15"}
      ]
    }
  ]
  
  
  // Second Invoice
  [
    {"date":0,"id":1,"products":
      [
        {"count":"1","format":"","id":"6921738073439","name":"pen","price":"15"}
      ]
    },
    {"date":0,"id":1,"products":
      [
        {"count":"1","format":"","id":"6921738073439","name":"pen","price":"15"}
      ]
    }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>UPDATE: I've also included my java code of how I'm creating the invoice:</p>
  
  <pre><code>  public void save(final Invoice object) {
          realm.executeTransactionAsync(new Realm.Transaction() {
              @Override
              public void execute(Realm realm) { 
                  realm.copyToRealmOrUpdate((Invoice) object);
              }
          }, new Realm.Transaction.OnSuccess() {
              @Override
              public void onSuccess() {
                  Log.i("***", "success");
              }
          }, new Realm.Transaction.OnError() {
              @Override
              public void onError(Throwable error) {
                  Log.i("***", error.toString());
              }
          });
      }
  </code></pre>