title: Rails JOIN TABLES
body: <p>i'm trying to use the GeoKit plugin to calculate the distance between 2 points. So the idea is, i do a search for an article, and the results i want to order by distance. So i have a form where I enter the article (that im looking for) and my address. Then rails must find all articles that match with my query and order by address.</p>
  
  <p>So now, i have two models: Article and User. Articles belongs_to User and User has_many Articles. At the User model i have the info related with my latitude and longitude.</p>
  
  <p>So my Article object has three fields:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>user_id (FK to User model)</li>
  </ul>
  
  <p>And my user model has four fields</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>lat (latitude)</li>
  <li>lng (longitude)</li>
  </ul>
  
  <p>OK, to have access to the user info thru articles i do the query:</p>
  
  <pre><code>@articles = Article.find(:all,:conditions=&gt;"vectors @@ to_tsquery('büch')",:joins=&gt;" INNER JOIN users ON users.id = articles.user_id",:include=&gt;:user,:origin=&gt;"Augustusplatz,8,leipzig,germany")
  </code></pre>
  
  <p>it works. But when i wanna add an :order=>'distance ASC' it fails because the order by query is using a Article.lat, and Article.lng fields to calculate the distance, but these fields lat and lng, are User object's members and not Article member.</p>
  
  <p>BTW if I get the query generated by rails and i change the order by clause where uses articles.lat/lng to users.lat/lng it works.</p>