title: Sorting an array of objects by a child's attribute
body: <p>I have an array of objects and I need to sort them based on their child's <code>average_score</code> attribute. I've tried with <code>sort!</code> but this doesn't seem to work, I'm not sure I can use Rails associations here:</p>
  
  <pre><code>collection.sort! do |a, b|
    a.children.where(:user_id =&gt; current_user.id).first.average_score &lt;=&gt; b.children.where(:user_id =&gt; current_user.id).first.average_score
  end
  </code></pre>
  
  <p>Can anyone suggest how I might do this?</p>