title: Rails: Serializing deeply nested associations with active_model_serializers
body: <p>I'm using <code>Rails 4.2.1</code> and <code>active_model_serializers 0.10.0.rc2</code></p>
  <p>I'm new to API's and chose <code>active_model_serializers</code> because it seems to be becoming the standard for rails (Although I'm not opposed to using <code>RABL</code> or another serializer)</p>
  <p>The problem I'm having is that I can't seem to include various attributes in multi-level relationships. For instance, I have:</p>
  <p><strong>Projects</strong></p>
  <pre><code>class ProjectSerializer &lt; ActiveModel::Serializer
    attributes                      :id, 
                                    :name,
                                    :updated_at
  
    has_many                        :estimates, include_nested_associations: true
  
  end
  </code></pre>
  <p>and <strong>Estimates</strong></p>
  <pre><code>class EstimateSerializer &lt; ActiveModel::Serializer
    attributes                      :id, 
                                    :name, 
                                    :release_version, 
                                    :exchange_rate, 
                                    :updated_at,
  
                                    :project_id, 
                                    :project_code_id, 
                                    :tax_type_id 
  
    belongs_to                      :project
    belongs_to                      :project_code
    belongs_to                      :tax_type
  
    has_many                        :proposals
  
  end
  </code></pre>
  <p><strong>Proposals</strong></p>
  <pre><code>class ProposalSerializer &lt; ActiveModel::Serializer
    attributes                      :id, 
                                    :name, 
                                    :updated_at,
  
                                    :estimate_id
  
    belongs_to                      :estimate
  end
  </code></pre>
  <p>When I hit the <code>/projects/1</code> the above produces:</p>
  <pre><code>{
    &quot;id&quot;: 1,
    &quot;name&quot;: &quot;123 Park Ave.&quot;,
    &quot;updated_at&quot;: &quot;2015-08-09T02:36:23.950Z&quot;,
    &quot;estimates&quot;: [
      {
        &quot;id&quot;: 1,
        &quot;name&quot;: &quot;E1&quot;,
        &quot;release_version&quot;: &quot;v1.0&quot;,
        &quot;exchange_rate&quot;: &quot;0.0&quot;,
        &quot;updated_at&quot;: &quot;2015-08-12T04:23:38.183Z&quot;,
        &quot;project_id&quot;: 1,
        &quot;project_code_id&quot;: 8,
        &quot;tax_type_id&quot;: 1
      }
    ]
  }
  </code></pre>
  <p>However, what I'd like it to produce is:</p>
  <pre><code>{
    &quot;id&quot;: 1,
    &quot;name&quot;: &quot;123 Park Ave.&quot;,
    &quot;updated_at&quot;: &quot;2015-08-09T02:36:23.950Z&quot;,
    &quot;estimates&quot;: [
      {
        &quot;id&quot;: 1,
        &quot;name&quot;: &quot;E1&quot;,
        &quot;release_version&quot;: &quot;v1.0&quot;,
        &quot;exchange_rate&quot;: &quot;0.0&quot;,
        &quot;updated_at&quot;: &quot;2015-08-12T04:23:38.183Z&quot;,
        &quot;project&quot;: { 
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;123 Park Ave.&quot;
        },
        &quot;project_code&quot;: {
          &quot;id&quot;: 8,
          &quot;valuation&quot;: 30
        },
        &quot;tax_type&quot;: {
          &quot;id&quot;: 1,
          &quot;name&quot;: &quot;no-tax&quot;
        },
        &quot;proposals&quot;: [
          {
            &quot;id&quot;: 1,
            &quot;name&quot;: &quot;P1&quot;,
            &quot;updated_at&quot;: &quot;2015-08-12T04:23:38.183Z&quot;
          },
          {
            &quot;id&quot;: 2,
            &quot;name&quot;: &quot;P2&quot;,
            &quot;updated_at&quot;: &quot;2015-10-12T04:23:38.183Z&quot;
          }
        ]
      }
    ]
  }
  </code></pre>
  <p>Ideally, I'd also like to be able to specify which attributes, associations, and attributes of those associations are included in each serializer.</p>
  <p>I've been looking through the AMS issues, and there does seem to be some back and forth on how this should be handled (or if this kind of functionality is even actually supported) but I'm having difficulty figuring out exactly what the current state is.</p>
  <ul>
  <li><a href="https://github.com/rails-api/active_model_serializers/issues/835" rel="nofollow noreferrer">https://github.com/rails-api/active_model_serializers/issues/835</a></li>
  <li><a href="https://github.com/rails-api/active_model_serializers/issues/968" rel="nofollow noreferrer">https://github.com/rails-api/active_model_serializers/issues/968</a></li>
  <li><a href="https://github.com/rails-api/active_model_serializers/issues/414" rel="nofollow noreferrer">https://github.com/rails-api/active_model_serializers/issues/414</a></li>
  <li><a href="https://github.com/rails-api/active_model_serializers/issues/444" rel="nofollow noreferrer">https://github.com/rails-api/active_model_serializers/issues/444</a></li>
  </ul>
  <p>One of the proposed solutions was to override the attribute with a method to call the nested attributes, but that seems to be regarded as a hack so I wanted to avoid it if possible.</p>
  <p>Anyway, an example of what of how to go about this or general API advice would be much appreciated.</p>