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"?
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}}
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.
精彩评论