Rails 3.0 Routing

singsunn
singsunn used Ask the Experts™
on
What is the Rails 3 Equivalent of this Rails 2 Route.

Team.count(
                  :joins => "INNER JOIN media on media_rep.id = media.media_rep_id"
                  :conditions => ["user_id = #{user_id} "],
                  :order => 'created_at DESC'
                )

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Whoops, that isn't a route.

You can use the above code in Rails 3.  The :order => 'created_at DESC' does nothing to affect the count, however, so you can remove it.

Author

Commented:
whoops .. what was i thinking .. i didnt mean to call it routes? but how do i rewrite this activerecord query ?

cause the one above gives me an error..
I could do something like  
Team.joins(".....").where("...") 

Open in new window

This would give me the whole resultset.. but i just need the count.
You are so close.  If you just need the number of records matching the query you can just call "count" at the end of your query chain.  Like this:

Team.joins("...").where("...").count

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial