Find all with :conditions on NULL values

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

On Oct 21, 12:27 pm, Jej [email protected] 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

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

Fred

Thanks a lot!