Search code examples
sqlruby-on-railsactiverecorddynamic-finders

Using dynamic finders to specify NOT NULL


I very often want to use dynamic finders to specify NOT NULL. So…

this works:

Widget.find_all_by_color('blue')

this works:

Widget.find_all_by_color(nil)

But how can I do

SELECT * FROM `widgets` WHERE `color` IS NOT NULL;

?


Solution

  • Try this:

    Widget.all(:conditions => "color IS NOT NULL")