Skip to content
Browse files

count join

  • Loading branch information...
1 parent 07b8774 commit 4515342acfe191418903d06e37be8d87aa4c940d @mynameisrufus committed Feb 19, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −1 app/controllers/stop_controller.rb
View
7 app/controllers/stop_controller.rb
@@ -14,7 +14,12 @@ def index
def search
name = params[:search]
- @stop_descriptions = StopDescription.where("tsndescription ilike ?", "%#{name}%")
+ @stop_descriptions = StopDescription.where("tsndescription ilike ?", "%#{name}%").joins("
+ INNER JOIN (
+ SELECT tsn, count(*) AS services FROM #{Stop.table_name}
+ GROUP BY tsn
+ ) AS t1 ON t1.tsn = #{StopDescription.table_name}.tsn"
+ ).order("services DESC")
render :stops
end

0 comments on commit 4515342

Please sign in to comment.
Something went wrong with that request. Please try again.