I am currently implementing this functionality in a monkey patch, and I'm wondering if there is sufficient interest in it to turn it into a real Rails patch with appropriate tests.
Right now, Foo.find(:all, :conditions => { :bar => baz }) will generate and execute SQL with conditions for the `bar` field equal to the baz variable. If baz is a Range object it will use BETWEEN instead of =. If baz is nil it will use IS NULL. If baz is an Array (or AssociationCollection) it will use IN.
The problem is that there is no way to express NOT IN, IS NOT NULL, NOT BETWEEN, <>, <, >, <=, or >=. I've implemented a way of expressing it. Here are some examples:
baz = { :operator => '<>', :value => 'quux' } SQL: "<> 'quux'"
baz = { :not => true, :value => nil } SQL: "IS NOT NULL"
baz = { :not => true, :value => 10..20 } SQL: "NOT BETWEEN 10 AND 20"
baz = { :not => true, :operator => '>', :value => 20 } SQL: "<= 20"
baz = { :not => true, :value => %w(foo bar baz quux) } SQL: "NOT IN ('foo', 'bar', 'baz', 'quux')"
As a monkey patch, my implementation is roughly 75 lines long. I suspect it would be smaller as a patch to ActiveRecord::Base (plus tests). Is there sufficient interest that I should put it in Trac as a feature request with a patch for implementation and tests?
--Greg