Reputation: 9722
So, if I do:
>> User.where("facebook_data IS null")
(0.5ms) SELECT COUNT(*) FROM `users` WHERE (facebook_data IS null)
=> []
If yet, I look up my user account:
>> u = User.find(225)
=> #<User id: 225, email: "[email protected]", ...etc>
>> u.facebook_data
=> nil
So I clearly have no facebook_data
. Why is this record not coming up when I use the where clause?
Upvotes: 1
Views: 211
Reputation: 9722
Ok so getting to the bottom of this, I went into mysql:
mysql> select users.facebook_data from users WHERE users.id = 225;
+---------------+
| facebook_data |
+---------------+
| ---
|
+---------------+
1 row in set (0.00 sec)
And then in the console..
> User.find(225).facebook_data == nil
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 225 LIMIT 1
=> true
So... ActiveRecord has somehow put "---" in the column instead of "NULL"...... And ActiveRecord recognizes "---" as null, but mysql disagrees.
Upvotes: 1