I want to use an array in the :conditions of an ActiveRecord Find so that a SQL IN statement is created. However, I also want to specify a greater than condition on a timestamp column too. From the Docs: An array may be used in the hash to use the SQL IN operator: Student.find(:all, :conditions => { :grade => [9,11,12] }) How do I modify this so that it also contains the timestamp condition? :condition => [''created_at > ?'',time] -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Hey... I''ve been doing Rails for a while and have never adopted the hash syntax for conditions. Someone else might be able to help you with that, but I know this will work: Student.find :all, :conditions = >["grade in (?) and created_at > ?", [9,11,12], time] On Fri, Jul 18, 2008 at 6:57 AM, Tim Conner < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I want to use an array in the :conditions of an ActiveRecord Find so > that a SQL IN statement is created. However, I also want to specify a > greater than condition on a timestamp column too. > From the Docs: > An array may be used in the hash to use the SQL IN operator: > Student.find(:all, :conditions => { :grade => [9,11,12] }) > > > How do I modify this so that it also contains the timestamp condition? > :condition => [''created_at > ?'',time] > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
On Jul 18, 2008, at 10:08 AM, Brian Hogan wrote:> Hey... > I''ve been doing Rails for a while and have never adopted the hash > syntax for conditions. Someone else might be able to help you with > that, but I know this will work: > > Student.find :all, :conditions = >["grade in (?) and created_at > > ?", [9,11,12], time]Yes, that''s it. If you like the Hash form for conditions, you might like DataMapper where the same query would look like: Student.all(:grade => [9,11,12], :created_at.gt => time) http://datamapper.org/ -Rob> On Fri, Jul 18, 2008 at 6:57 AM, Tim Conner <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > > wrote: > > I want to use an array in the :conditions of an ActiveRecord Find so > that a SQL IN statement is created. However, I also want to specify a > greater than condition on a timestamp column too. > From the Docs: > An array may be used in the hash to use the SQL IN operator: > Student.find(:all, :conditions => { :grade => [9,11,12] }) > > > How do I modify this so that it also contains the timestamp condition? > :condition => [''created_at > ?'',time]Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---