In Rails 3.0.9 (Ruby 1.9.2, MySQL) I have a method that is supposed to find users using two fields, type(string) and flag(boolean). The string part of the query works fine, but not the boolean part.
here's the code:
def find_users(type)
@private_users = User.where('type =? and flag != ?', org_type, true)
end
to try to figure out what's going on, put this code:
@users.each do |f|
puts "oh helllllllllllllllllllllllllllo #{f.user_name}"
puts "oh helllllllllllllllllllllllllllo #{f.flag}"
puts "oh helllllllllllllllllllllllllllo #{f.type}"
end
The flag field is blank/null for most of these and those are the ones I'm trying to pick up.
If I change the expression to ('type =? and flag = ?', type, true), it correctly finds the ones where 1 is the value of the flag.
I've tried these things to no avail:
User.where('type =? and flag = ?', org_type, false)
User.where('type =? and flag = ?', org_type, "")
User.where('type =? and flag = ?', org_type, nil)
This probably an easy question for someone, so I hoping some knows the answer. Thank you!