sadeesh kumar viswanathan
2008-Dec-03 16:45 UTC
need flexible conditions hash with activerecord
Hi, I am using find method of activerecord in my code. And I am specifying conditions through hash like below, conditions = {} conditions[:deactivated_on] = !nil (conditions[:deactivated_on] = nil - this works) @accounts = Account.paginate :page=>params [:page], :per_page=>20, :order=>"name", :conditions=>conditions I want all accounts where deactivated_on != NULL. I could not make this work with conditions hash. Its working with normal conditions like ["deactivated_on is not null"]. But I am in need of use it with hash conditions because of existing code. With conditions hash no more conditions are allowed except ''='' as far I tried. Ex: age = 18 - could be done with conditions hash age <18,age >18 (other than ''='') - could not be done with conditions hash. Can anyone have clear idea to explain me? Thanks, Sadeesh. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
actually u can make range conditions... like :conditions=>{:created_at => 17.days.ago..Time.now} or :conditions=>{:some_attribute=>[1,2,3,4,5,6,7]} which will be translated to "in (1,2,3,4,5,6,7)" i''m not sure about the "is not null" part though On Wed, Dec 3, 2008 at 6:45 PM, sadeesh kumar viswanathan < sadathiru-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > I am using find method of activerecord in my code. And I am > specifying conditions through hash like below, > conditions = {} > conditions[:deactivated_on] = !nil (conditions[:deactivated_on] = nil > - this works) > @accounts = Account.paginate :page=>params > [:page], :per_page=>20, :order=>"name", :conditions=>conditions > > I want all accounts where deactivated_on != NULL. I could not make > this work with conditions hash. Its working with normal conditions > like ["deactivated_on is not null"]. But I am in need of use it with > hash conditions because of existing code. > > With conditions hash no more conditions are allowed except ''='' as far > I tried. > > Ex: > age = 18 - could be done with conditions hash > age <18,age >18 (other than ''='') - could not be done with conditions > hash. > > Can anyone have clear idea to explain me? > > Thanks, > Sadeesh. > > >-- Mahmoud Said Software Developer blog.modsaid.com www.eSpace.com.eg +20-16-1223857 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---