activerecord - how to modify complex sql query w/ join into rails 3 -


i'm working on car pooling application users can add lifts , able select multiple stops each lift ( b via c, d, e). when user searches database lift results should include lifts 'a d', 'c b' or 'c e' , on.

got working rails 2.3.5 using below code struggle moving on rails 3. i'm sure there must cleaner way achieve i'm trying , move code model.

it great if me on one.

class lift < activerecord::base   has_many :stops end  class stop < activerecord::base              belongs_to :lift   belongs_to :city   end  class city < activerecord::base   has_one :stop end   @lifts = lift.find(   :select =>     "lifts.id, bs.city_id start_city_id, bs2.city_id destination_city_id",   :from =>       "lifts",   :joins =>      "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 =>    [:stops, :cities],   :conditions => "bs.lift_id = bs2.lift_id , bs.position < bs2.position"                   #uses position attribute determine order of stops ) 

i know simple answer why not create scope in model these options?


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -