I'm trying to recreate the following syntax using squeel by using a loop:

```
WHERE season = "value" OR season IS NULL

```

I was able to get this far:

```
where do
  ((season == entry["season"]) | (season == nil)) &
  ((episode == entry["episode"]) | (episode == nil)) &
  ((imdb == entry["imdb"]) | (imdb == nil)) &
  (YEAR(theatrical) == year)

```

However, the problem is I want to do it **in a loop** so I don't have to do conditionals for when the values are empty (for example if imdb doesn't have a value I wouldn't even use that line).

I have this:

```
entry = { "imdb"=>"0364725", "media"=>"DVD", "season"=>"1", ...}
entry.each do |k,v|
    ((k == v) | (k == nil))
  end
end

```

But it does not put the `field IS NULL` bit in the SQL. 

If it's not possible with Squeel, might it be done with ActiveRecord?

Ultimately, I'm looking for a way to avoid having conditionals for those fields in the SQL. As I said above, if the field is empty I don't list them at all, but if it has a value I need to do the whole `field = value OR field IS NULL` bit.

Any help would be greatly appreciated.

**Edit:**

The whole code I'm trying to use at the moment is this:

```
matches_found = 
includes(:dvd_director, :dvd_upc, :dvd_series).limit(1).
where do
  (title == title_to_search) &
  entry.each { |k,v| ((k == v) | (k == nil)) }
end

```

Note that everything after the `|` is getting ignored whether I use `__send__(k)` or not.

**More info:**
One very strange thing is that if I use anything other than the `k,v` it gets ignored. For example:

```
    entry.each { |k,v| ((k == "bob") | (k == v)) }

```

"Bob" gets ignored! and the value (v) gets put into the SQL without the `OR` statement.