title: How to convert an active record with associations to a nested hash?
body: <p>SO...</p>
  
  <p>I am writing some code that will query an active record with associations and return the data in a format similar to...</p>
  
  <pre><code>[{
      foo: {
          id: ...,
          foo_property: ... 
      },
      bar: {
          id: ...,
          bar_property: ...
      }
  }, ...]
  </code></pre>
  
  <p>...the top level active record and its associations all have timestamps and other fields I would like to exclude. I am aware of <code>attributes</code> and <code>as_json</code> but both of these do not follow relationships (instead replacing foo and bar with foo_id and bar_id). I am also aware of <code>AssociationReflection</code> and its ability to dynamically find associations that can with some complexity perform what I would like, but ideally...</p>
  
  <p>I want a simple, elegant way to query my data with this transformation and property filtering, i.e.</p>
  
  <pre><code>Whatever.joins(:foos, :bars)
          .eager_load(:foos, :bars)
          .? # convert results to an array of hashes with association data (under appropriately named hash key)
          .? # filter top level entries and association data to not have timestamps, etc. (select?)
  </code></pre>
  
  <p>...thanks!</p>