title: Insert object from JSON into Realm with relation based on ID
body: <p>I want to fetch some objects from my server and receive them as JSON objects and adding them to realm using <code>insertOrUpdate()</code>.</p>
  
  <p>Currently, nested / related objects are send in whole by the server and realm does its magic inserting and relating those to each other - working perfectly.</p>
  
  <p>The list of <code>Foo</code> I receive from the server looks like this (<code>Bar</code> is copied for each reference):</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Foo 1",
      "bar": [
        {
          "id": 1,
          "name": "Bar 1"
        },
        {
          "id": 2,
          "name": "Bar 2"
        }
      ]
    },
    {
      "id": 2,
      "name": "Foo 2",
      "bar": [
        {
          "id": 2,
          "name": "Bar 2"
        }
      ]
    }
  ]
  </code></pre>
  
  <p>But this means much more data to be transmitted because shared objects (e.g. <code>Bar</code> with ID <code>2</code>) are duplicated in the JSON.</p>
  
  <p>Is there a way to have only the ID of the shared object in the JSON but let realm link them to the correct objects?</p>
  
  <p>So only the ID of the referenced objects are stated in the JSON (and I would need to fetch those objects as well - maybe before?):</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Foo 1",
      "bar": [
        1,
        2
      ]
    },
    {
      "id": 2,
      "name": "Foo 2",
      "bar": [
        2
      ]
    }
  ]
  </code></pre>
  
  <p>Is this possible? What's the best practice to reduce traffic when many / big objects are shared?</p>