Forgive this question, but I''m new to rails, and my SQL is rather rusty. I have a line like so to get all records for a particular time period: @recordings_for_period = Recording.find(:all, :order => "date_of_event DESC", :conditions => ["date_of_event >= ? AND date_of_event < ?", start_date, end_date]) Let say, instead, I just want to know the number of recordings that are available for that time period. Should I just run the above code and then get the length of the array? Or is there some construction I should be using with COUNT that would be better? (I.e., is less work for the database to process.) Oh, and (unfortunately) I am still using rails 2.3.5. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 27 Aug, 06:13, Terry Michaels <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Forgive this question, but I''m new to rails, and my SQL is rather rusty. > I have a line like so to get all records for a particular time period: > > @recordings_for_period = Recording.find(:all, :order => "date_of_event > DESC", :conditions => ["date_of_event >= ? AND date_of_event < ?", > start_date, end_date]) > > Let say, instead, I just want to know the number of recordings that are > available for that time period. Should I just run the above code and > then get the length of the array? Or is there some construction I should > be using with COUNT that would be better? (I.e., is less work for the > database to process.)There''s a count method that does what you want Fred> > Oh, and (unfortunately) I am still using rails 2.3.5. > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 27 August 2010 06:13, Terry Michaels <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Forgive this question, but I''m new to rails, and my SQL is rather rusty. > I have a line like so to get all records for a particular time period: > > @recordings_for_period = Recording.find(:all, :order => "date_of_event > DESC", :conditions => ["date_of_event >= ? AND date_of_event < ?", > start_date, end_date]) > > Let say, instead, I just want to know the number of recordings that are > available for that time period. Should I just run the above code and > then get the length of the array? Or is there some construction I should > be using with COUNT that would be better? (I.e., is less work for the > database to process.)@count_of_recordings_for_period = Recording.count(:all, :order => "date_of_event DESC", :conditions => ["date_of_event >= ? AND date_of_event < ?", start_date, end_date]) should use COUNT in the sql to give the answer you want. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.