views:

27

answers:

1

hi,

Course.find(:all, :group =>:id, :order => 'updated_at DESC', :joins=> :students  :conditions => { :students =>  { :first_name=>"John", :status => 1}})

looking this query, passing the conditions as a hash, there is a way to:

  • construct a where :first_name not null?
  • construct a where :first_name != "John"?
+1  A: 

Natively, there is not a way of which I am aware. There is ar-extensions which extends the finders with many things, including negating.

:conditions => { :students =>  { :first_name_not => "John"}}
:conditions => { :students =>  { :first_name_not => nil}}

There is a good writeup here: http://continuousthinking.com/are

Fair warning, last update I see for it is a year ago and support is limited to postgre, mysql and sqlite. This is the only active project I am aware of that extends activerecord in this way. Thoughtbot had squirrel, which you might be able to find some active forks for.

Geoff Lanotte