title: Rails Serialization - fast_jsonapi / active_model_serializers
body: <p>I am a bit lost getting on board fast_jsonapi / active_model_serializers to build an API.  I have the basics down but seem stuck on a custom solution.</p>
  
  <p>I have this as a serializer:</p>
  
  <pre><code>class AreaSerializer
    include FastJsonapi::ObjectSerializer
    attributes :id, :name, :cost_center, :notes
    has_many :children
  end
  </code></pre>
  
  <p>In my area model I have:</p>
  
  <pre><code>  has_many :children, -&gt; { Area.where(ancestry: id) }
  </code></pre>
  
  <p>My controller looks like:</p>
  
  <pre><code>class Api::V1::AreasController &lt; ApiController
  
    def index
      render json: AreaSerializer.new(Area.root).serialized_json
    end
  
  end
  </code></pre>
  
  <p>Areas are nested in a hierarchy with the ancestry gem.  The output is:</p>
  
  <pre><code>{
  "data": [{
      "id": "1",
      "type": "area",
      "attributes": {
          "id": 1,
          "name": "Calgary",
          "cost_center": "123456",
          "notes": ""
      },
      "relationships": {
          "children": {
              "data": [{
                  "id": "3",
                  "type": "child"
              }]
          }
      }
  }, {
      "id": "2",
      "type": "area",
      "attributes": {
          "id": 2,
          "name": "Edmonton",
          "cost_center": "78946",
          "notes": ""
      },
      "relationships": {
          "children": {
              "data": []
          }
      }
  }]
  </code></pre>
  
  <p>}</p>
  
  <p>I am looking for an out put like this:</p>
  
  <pre><code>{
  "data": [{
      "id": "1",
      "type": "area",
      "attributes": {
          "id": 1,
          "name": "Calgary",
          "cost_center": "123456",
          "notes": ""
      },
      "relationships": {
          "areas": {
              "data": [{
                  "id": "3",
                  "type": "area",
                  "attributes": {
                      "id": 3,
                      "name": "Child Area",
                      "cost_center": "123456",
                      "notes": ""
                  }
              }]
          }
      }
  }, {
      "id": "2",
      "type": "area",
      "attributes": {
          "id": 2,
          "name": "Edmonton",
          "cost_center": "78946",
          "notes": ""
      }
  }]
  </code></pre>
  
  <p>}</p>
  
  <p>The idea being where the nested relationship shows the details etc.</p>