title: Ransack Sorting Association
body: <p>I've been troubleshooting this for a while and have seen a couple issues that seem to describe my problem but none of the solutions work.</p>
  
  <p>I have two models property and listings, I want to add a sort link that will sort a list of properties by a field on the listing.</p>
  
  <p>My models look like:</p>
  
  <pre><code>class Property &lt; ApplicationRecord
    has_many :listings
  end
  
  
  class Listing &lt; ApplicationRecord
    belongs_to :property
  end
  </code></pre>
  
  <p>Controller does:</p>
  
  <pre><code>@q =Property.joins(:listings).select('id', 'full_address', 'price_pence', 'first_listed_date', 'property_type', 'bedrooms', 'listings.agency').ransack(params[:q])
  @properties = @q.result
  </code></pre>
  
  <p>So how do I make my sort link work?</p>
  
  <pre><code>&lt;%= sort_link(@q, :listing_agency, 'Agency') %&gt;
  </code></pre>