Hi All, In my application I have users that have a ''last_login'' attribute. I''m trying do a find for all users that have not logged in for over a month but I''m having a little trouble figuring out how to do this with activerecord. Does anyone know how to do this, or do I have to use SQL? --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Glaesemann
2007-Oct-09 12:36 UTC
Re: find all users who haven''t logged in for a while
On Oct 9, 2007, at 7:24 , jeroen wrote:> I''m > trying do a find for all users that have not logged in for over a > month but I''m having a little trouble figuring out how to do this with > activerecord.# sql version sql = <<-SQL select * from users where last_login < current_timestamp - interval ''1 month'' SQL users_on_vacation = Users.find_by_sql(sql) # first ActiveRecord version users_on_vacation = Users.find(:all, :conditions => [%(last_login < current_timestamp - interval ''1 month'')]) # second ActiveRecord version users_on_vacation = Users.find(:all, :conditions => [%(last_login < ?), 1.month.ago]) Michael Glaesemann grzm seespotcode net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---