title: JSON API style sideloading in Rails ActiveModel::Serializers
body: <p>I'm trying to build a <a href="http://jsonapi.org/format/" rel="noreferrer">JSON API</a> style API using AM::Serializer. I'm running into an issue with sideloading.</p>
  
  <p>I want to be able to build JSON that looks like:</p>
  
  <pre><code>{
      "primaries": [{
          "id": 123,
          "data": "Hello world.",
          "links": {
              "secondaries": [ 1, 2, 3 ]
          }
      }],
      "linked" : {
          "secondaries": [
              {
                  "id": 1,
                  "data": "test1"
              },
              {
                  "id": 2,
                  "data": "test2"
              },
              {
                  "id": 3,
                  "data": "test3"
              }
          ]
      }
  }
  </code></pre>
  
  <p>The code I've been able to come up with looks like:</p>
  
  <pre><code>class PrimarySerializer &lt; ActiveModel::Serializer
    attributes :id, :data
  
    has_many :secondaries, key: :secondaries, root: :secondaries
    embed :ids, include: true
  end
  </code></pre>
  
  <p>Which generates JSON that looks like:</p>
  
  <pre><code>{
      "primaries": [{
          "id": 123,
          "data": "Hello world.",
          "secondaries": [ 1, 2, 3 ]
      }],
      "secondaries": [
          {
              "id": 1,
              "data": "test1"
          },
          {
              "id": 2,
              "data": "test2"
          },
          {
              "id": 3,
              "data": "test3"
          }
      ]
  }
  </code></pre>
  
  <p>Is there a way to override the location of the in-element <code>secondaries</code> and sideloaded <code>secondaries</code> such that they live in child nodes <code>link</code> and <code>linked</code>?</p>
  
  <p>The above code is an abstraction of the actual code and may not work. Hopefully it illustrates the point sufficiently.</p>
  
  <p>Thanks!</p>