我該如何做以下兩個查詢的組合?ActiveRecord:如何查找boolean字段不正確的記錄?
1.9.3-p484 :003 > u = User.where(guest: false).count
(2.4ms) SELECT COUNT(*) FROM `users` WHERE `users`.`guest` = 0
=> 0
1.9.3-p484 :004 > u = User.where(guest: nil).count
(2.5ms) SELECT COUNT(*) FROM `users` WHERE `users`.`guest` IS NULL
=> 4150
我想抓住guest列(在一個語句中)有nil或false值的用戶。
請注意,.where.not(guest:true)查詢可能會忽略guest的零值,即可能等於where(guest:false)。至少它在Rails 4.1 + Postgres中。請參閱https://github.com/rails/rails/issues/11702 –