sco*_*ott 3 ruby null activerecord ruby-on-rails
我希望能够收集user_id不为null的表中的所有记录.这就是我所拥有的,但它似乎没有起作用(即使我已经在一个单独的项目中工作):
named_scope :all_registered, :conditions => ["user_id != ?", nil]
Run Code Online (Sandbox Code Playgroud)
SQL有一个特定的运算符来检查NULL:IS NULL和IS NOT NULL
named_scope :all_registered, :conditions => ["user_id IS NOT NULL"]
Run Code Online (Sandbox Code Playgroud)