2010-07-28 36 views
0

Course.find(:all,:group =>:id,:order =>'updated_at DESC',:joins =>:students:conditions => {:students => {:first_name = > 「約翰」:狀態=> 1}})rails將哈希條件加入

尋找這個查詢,傳遞條件的哈希,還有一個辦法:

  • 構造,其中:FIRST_NAME沒有空?
  • 構造一個where:first_name!=「John」?

回答

1

從本質上講,我沒有辦法知道。有ar-extensions這擴大了發現者許多事情,包括否定。

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

公平的警告,最後更新我看到它是一年前,支持僅限於postgre,mysql和sqlite。這是我知道的唯一活動項目,它以這種方式擴展了activerecord。 Thoughtbot有squirrel,你可能會找到一些活躍的分支。