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. -=- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Aaron Baldwin
2006-Sep-25 04:40 UTC
Re: Paginate and getting count of total number of records
On Sep 24, 2006, at 4:49 PM, Neeraj Kumar 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Neeraj Kumar
2006-Sep-25 12:27 UTC
Re: Paginate and getting count of total number of records
Thanks On 9/25/06, Aaron Baldwin <baldwina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Sep 24, 2006, at 4:49 PM, Neeraj Kumar 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---