# Need flexible conditions hash with activerecord

**URL:** <https://www.ruby-forum.com/t/need-flexible-conditions-hash-with-activerecord/154762>\
**Category:** Rails\
**Created:** [December 3, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/need-flexible-conditions-hash-with-activerecord/154762 "2008-12-03T17:46:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sadathiru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@sadathiru](https://www.ruby-forum.com/u/sadathiru)\
**Post date:** [December 3, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/need-flexible-conditions-hash-with-activerecord/154762/1 "2008-12-03T17:46:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sadathiru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@sadathiru](https://www.ruby-forum.com/u/sadathiru)\
**Post date:** [December 3, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/need-flexible-conditions-hash-with-activerecord/154762/2 "2008-12-03T18:28:28Z")

</div>

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 \<  
removed\_email\_address@domain.invalid\> wrote:

> I want all accounts where deactivated\_on != NULL. I could not make  
> hash.
> 
> Can anyone have clear idea to explain me?
> 
> Thanks,  
> Sadeesh.
> 
> >

–  
Mahmoud Said  
Software Developer

> **[Thoughts](http://blog.modsaid.com)**

www.eSpace.com.eg  
+20-16-1223857
