問題
DBの状態
dbにカラム foobar で nil x5、false x1、true、x0。
true以外が計6コ。
User.where(:foobar => nil).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` IS NULL => 5 User.where(:foobar => false).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` = 0 => 1 irb(main):064:0> User.where(:foobar => true).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` = 1 => 0
検索してみる
User.where("foobar != ?", true).count (0.4ms) SELECT COUNT(*) FROM `users` WHERE (foobar != 1) => 1
falseだけ取れた。
User.where("completed = ? or completed =?", nil, false).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE (completed = NULL or completed =0) => 1
falseだけ取れた?
User.where(:foobar => nil).where(:foobar => false).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` IS NULL AND `users`.`foobar` = 0 => 0
当たり前だにうまくいかない。