title: how to modify complex sql query w/ join into rails 3
body: <p>I'm working on a car pooling application where users can add lifts and are able to select multiple stops for each lift ( A to B via c, d, e). Now when a user searches the database for a lift the results should also include lifts like 'A to d', 'c to B' or 'c to e' and so on.<br/><br/>
  I got this working with Rails 2.3.5 using the below code but struggle moving it over to Rails 3. I'm sure there must be a cleaner way to achieve what i'm trying to do and move some code to the model.</p>
  
  <p>it would be great if someone could help me on this one.</p>
  
  <pre><code>class Lift &lt; ActiveRecord::Base
    has_many :stops
  end
  
  class Stop &lt; ActiveRecord::Base           
    belongs_to :lift
    belongs_to :city  
  end
  
  class City &lt; ActiveRecord::Base
    has_one :stop
  end
  
  
  @lifts = Lift.find(
    :select =&gt;     "lifts.id, bs.city_id as start_city_id, bs2.city_id as destination_city_id",
    :from =&gt;       "lifts",
    :joins =&gt;      "LEFT JOIN stops bs ON lifts.id = bs.lift_id
                    LEFT JOIN stops bs2 ON lifts.id = bs2.lift_id
                    JOIN cities bc ON bs.city_id = bc.id
                    JOIN cities bc2 ON bs2.city_id = bc2.id",
    :include =&gt;    [:stops, :cities],
    :conditions =&gt; "bs.lift_id = bs2.lift_id AND bs.position &lt; bs2.position"
                    #uses the position attribute to determine the order of the stops
  )
  </code></pre>