title: Properly formatting Ember custom serializer response for sideloaded JSON API data
body: <p>I want to try serving <a href="https://guides.emberjs.com/v2.17.0/models/customizing-serializers/" rel="nofollow noreferrer">sideloaded data</a> to my Ember app. I have a <code>city</code> model which <code>hasMany</code> <code>fireStations</code>. I changed my <code>hasMany</code> relationship to have an <code>{ async: false }</code> option to coincide with sideloading, since the data will no longer be loaded asynchronously.</p>
  
  <p>I use a custom serializer, and I am logging the response from <code>normalize()</code>. It looks like this for my data.</p>
  
  <pre><code>{
    "data": {
      "id": "3",
      "type": "city",
      "attributes": {
        "name": "Anytown USA"
      },
      "relationships": {
        "fireStations": {
          "data": [
            {
              "id": "17",
              "type": "fire-station"
            },
            {
              "id": "18",
              "type": "fire-station"
            }
          ]
        }
      }
    },
    "included": [
      {
        "id": "17",
        "type": "fire-station",
        "attributes": {
          "name": "North Side Fire Station"
        },
        "relationships": {}
      },
      {
        "id": "18",
        "type": "fire-station",
        "attributes": {
          "name": "East Side Fire Station"
        },
        "relationships": {}
      }
    ]
  }
  </code></pre>
  
  <p>I <em>think</em> my sideloaded data is properly formatted. It seems to match the <a href="https://guides.emberjs.com/v2.17.0/models/customizing-serializers/#toc_sideloaded-data" rel="nofollow noreferrer">example in the guides</a>. The <code>included</code> array is populated with all my sideloaded data, and it all seems to be formatted as needed.</p>
  
  <p>However, I'm hitting this error in my app.</p>
  
  <blockquote>
    <p>Assertion Failed: You looked up the 'fireStations' relationship on a 'city' with id 3 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('DS.hasMany({ async: true })')</p>
  </blockquote>
  
  <p>According to the JSON API spec, the format I am using seems to be correct for loading <a href="http://jsonapi.org/format/#document-compound-documents" rel="nofollow noreferrer">compound documents</a>.</p>
  
  <blockquote>
    <p>In a compound document, all included resources MUST be represented as an array of resource objects in a top-level <code>included</code> member.</p>
  </blockquote>
  
  <p>And it seems <a href="http://jsonapi.org/format/#document-resource-object-links" rel="nofollow noreferrer">links</a> are optional, so it should be fine that I am leaving them out.</p>
  
  <blockquote>
    <p>The optional <code>links</code> member within each resource object contains links related to the resource.</p>
  </blockquote>
  
  <p>I can't figure out what the issue is here. I forked <a href="https://github.com/emberjs/data" rel="nofollow noreferrer">ember-data</a> locally and I do indeed see <a href="https://github.com/emberjs/data/blob/master/addon/-private/system/relationships/state/has-many.js#L270" rel="nofollow noreferrer">this assertion is triggered</a>.</p>
  
  <p>If I manually loop over the <code>manyArray</code> in <code>has-many.js</code>, I see that each record is marked as <code>isEmpty</code> being <code>true</code></p>
  
  <p>Why are the <code>has-many</code> records returning <code>isEmpty === true</code>? What might I be doing wrong that is preventing sideloading from working correctly?</p>