I am using paginate to get the list of events from my database. Besides
pagination I also want to display the total number of records.
I noticed that the paginate query inside does do a SQL query to get the
total numbe of records. Is there a way to tap that count rather than
a separate query to just to get the count of records.
My existing pagination query is given below.
@query_join = "JOIN venues ON venues.id = events.venue_id " @query_join << "JOIN cities ON cities.id = venues.city_id" @event_pages, @events = paginate :events, :joins => @query_join, :conditions => ["start_date > ? ",Time.now], :per_page => per_page, :order => :start_date, :select => "events.*"
The generate query in the log:
SELECT count(*) AS count_all FROM events JOIN venues ON venues.id =
events.venue_id JOIN cities ON cities.id = venues.city_id WHERE
‘2006-09-25 04:01:17’ )
SELECT events.* FROM events JOIN venues ON venues.id = events.venue_id
cities ON cities.id = venues.city_id WHERE (start_date > ‘2006-09-25
04:01:17’ ) ORDER BY start_date LIMIT 0, 10