# EZ\_Where help, field IS NULL

**URL:** <https://www.ruby-forum.com/t/ez-where-help-field-is-null/71851>\
**Category:** Rails\
**Created:** [October 11, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/ez-where-help-field-is-null/71851 "2006-10-11T21:14:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [October 11, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/ez-where-help-field-is-null/71851/1 "2006-10-11T21:14:35Z")

</div>

I am trying to create a conditions caluse with ez\_where that looks like:

[“enabled = ? AND age\_min \<= ? AND (age\_max \>= ? OR age\_max IS NULL)”,  
true, range[:max], range[:min]]

Everything is fine except for the last part: “OR age\_max IS NULL”

The problem seems to stem that ez\_where does not provide a way to use  
“IS NULL” and “IS NOT NULL”. Here is what I tried so far:

```
conditions = Caboose::EZ::Condition.new do
  enabled == true
  age_min <= range[:max]
  any do
    age_max >= range[:min]
    age_max == nil
  end
end

```

But this leaves that last clause out resulting in:  
“enabled = ? AND age\_min \<= ? AND (age\_max \>= ?)”

I had some minor luck with using append inside the any block:

any do  
age\_max \>= range[:min]  
append ‘age\_max IS NULL’  
end

however this generates the appended clause with an AND instead of an OR.

Any tips?

---

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [October 11, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/ez-where-help-field-is-null/71851/2 "2006-10-11T22:18:54Z")

</div>

Hi Alex-

On Oct 11, 2006, at 12:14 PM, Alex W. wrote:

> The problem seems to stem that ez\_where does not provide a way to use
> 
> however this generates the appended clause with an AND instead of  
> an OR.
> 
> Any tips?

```
You can't just use nil on the right hand side of an ez_where

```

expression because it will leave out that expression as you  
discovered. This is so you don’t have to say

foo == params[:bar] if params[:bar]

you can leave off the if part and if params[:bar] is nil that  
statement will be left out of the query. This makes complex queried  
way easier to write. But it also makes IS NULL a special case so  
there is a special syntax for that:

```
 conditions = EZ::Where::Condition.new do
   enabled == true
   age_min <= range[:max]
   any do
     age_max >= range[:min]
     age_max == :null
   end
 end

```

Also it looks like you are using an old version, please update to the  
latest here:

svn checkout svn://rubyforge.org/var/svn/ez-where

So for now the way to do IS NULL and IS NOT NULL is liek this:

# IS NULL

foo == :null

# IS NOT NULL

foo! == :null

or append like you used.

-Ezra

---

<div class="post-metadata">

**Author:** ![squeegy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@squeegy](https://www.ruby-forum.com/u/squeegy)\
**Post date:** [October 11, 2006, 11:50pm UTC](https://www.ruby-forum.com/t/ez-where-help-field-is-null/71851/3 "2006-10-11T23:50:25Z")

</div>

Ezra Z. wrote:

> you can leave off the if part and if params[:bar] is nil that  
> statement will be left out of the query. This makes complex queried  
> way easier to write. But it also makes IS NULL a special case so  
> there is a special syntax for that:
> 
> ```
> conditions = EZ::Where::Condition.new do
> enabled == true
> age_min <= range[:max]
> any do
> age_max >= range[:min]
> age_max == :null
> end
> end
> 
> ```
> 
> Also it looks like you are using an old version, please update to the  
> latest here:
> 
> svn checkout svn://rubyforge.org/var/svn/ez-where

Ah, I was linked to a non rubyforge svn somehow. Patched up and using  
:null and all is well.

Thanks for the awesome plugin, Ezra.
