# Find all with :conditions on NULL values

**URL:** <https://www.ruby-forum.com/t/find-all-with-conditions-on-null-values/177643>\
**Category:** Rails\
**Created:** [October 21, 2009, 1:28pm UTC](https://www.ruby-forum.com/t/find-all-with-conditions-on-null-values/177643 "2009-10-21T13:28:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b782af/32.png) [@Jej](https://www.ruby-forum.com/u/Jej)\
**Post date:** [October 21, 2009, 1:28pm UTC](https://www.ruby-forum.com/t/find-all-with-conditions-on-null-values/177643/1 "2009-10-21T13:28:45Z")

</div>

Hi all,

I don’t understand why this does not work:

Model.all(:conditions =\> [“first\_category\_id = ?”, nil]) or Model.all  
(:conditions =\> “first\_category\_id = NULL”)

to get all records having NULL in first\_category\_id.

This works instead:

Model.all(:conditions =\> “first\_category\_id IS NULL”)

I wonder why it’s not possible to use the activerecord way?

Is there a proper way to get all records that have or miss a  
relationship?

Cheers,  
Jej

---

<div class="post-metadata">

**Author:** ![Jej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b782af/32.png) [@Jej](https://www.ruby-forum.com/u/Jej)\
**Post date:** [October 21, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/find-all-with-conditions-on-null-values/177643/2 "2009-10-21T13:35:12Z")

</div>

On Oct 21, 12:27 pm, Jej [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Model.all(:conditions =\> “first\_category\_id IS NULL”)
> 
> I wonder why it’s not possible to use the activerecord way?

It does work if you use the hash form of conditions ( ie conditions =\>  
{:first\_category\_id =\> foo} )

Fred

---

<div class="post-metadata">

**Author:** ![Jej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b782af/32.png) [@Jej](https://www.ruby-forum.com/u/Jej)\
**Post date:** [October 22, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/find-all-with-conditions-on-null-values/177643/3 "2009-10-22T23:19:10Z")

</div>

> It does work if you use the hash form of conditions ( ie conditions =\>  
> {:first\_category\_id =\> foo} )
> 
> Fred

Thanks a lot!
