title: Rails - Sort by join table data
body: <p>I've got a RoR project in the works. Here are the applicable sections of my models.</p>
  
  <p><strong>Home</strong></p>
  
  <pre><code>has_many :communities, :through =&gt; :availabilities
  has_many :availabilities, :order =&gt; "price ASC"
  </code></pre>
  
  <p><strong>Community</strong></p>
  
  <pre><code>has_many :homes, :through =&gt; :availabilities
  has_many :availabilities
  </code></pre>
  
  <p><strong>Availability</strong></p>
  
  <pre><code>belongs_to :home
  belongs_to :community
  </code></pre>
  
  <p><em>The "availabilities" table in the database has the additional data column "price"</em></p>
  
  <p>So now I can call</p>
  
  <pre><code>@home.availabilities.each do |a|
    a.community.name
    a.price
  </code></pre>
  
  <p>and get back the availabilities data ordered by price as I want. My question is this:</p>
  
  <p>Is there a way to automatically order Homes by <code>avaliabilities.first.price</code> (first = lowest)? Maybe something with <code>default_scope :order</code>?</p>