Paginate and getting count of total number of records

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
having
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
(start_date

‘2006-09-25 04:01:17’ )

SELECT events.* FROM events JOIN venues ON venues.id = events.venue_id
JOIN
cities ON cities.id = venues.city_id WHERE (start_date > ‘2006-09-25
04:01:17’ ) ORDER BY start_date LIMIT 0, 10

Thanks.
-=-

On Sep 24, 2006, at 4:49 PM, Neeraj K. wrote:

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 having a separate query to just to get the count of records.

@event_pages.item_count

Aaron

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs