我的数据库中有数据,由于某些原因,我能够找到一些记录但不能找到其他记录。这是一个例子。
记录104:
2.1.1 :016 > m = Message.find(104)
Message Load (0.4ms) SELECT `messages`.* FROM `messages` WHERE `messages`.`id` = 104 LIMIT 1
=> #<Message id: 104, subject: "tokened?", body: "token test", created_at: "2014-04-20 22:03:35", updated_at: "2014-04-20 22:03:48", token: "C5RUmoKzUoAQ3gKvCh0Bew">
按令牌搜索记录104(成功):
2.1.1 :017 > m = Message.where(token: 'C5RUmoKzUoAQ3gKvCh0Bew').first
Message Load (0.4ms) SELECT `messages`.* FROM `messages` WHERE `messages`.`token` = 'C5RUmoKzUoAQ3gKvCh0Bew' ORDER BY `messages`.`id` ASC LIMIT 1
=> #<Message id: 104, subject: "tokened?", body: "token test", created_at: "2014-04-20 22:03:35", updated_at: "2014-04-20 22:03:48", token: "C5RUmoKzUoAQ3gKvCh0Bew">
记录106:
2.1.1 :021 > m = Message.find(106)
Message Load (0.6ms) SELECT `messages`.* FROM `messages` WHERE `messages`.`id` = 106 LIMIT 1
Message Exists (0.4ms) SELECT 1 AS one FROM `messages` WHERE `messages`.`token` = '8yE5HGJLv5jqOr4azEDxHQ' LIMIT 1
=> #<Message id: 106, subject: "2nd token", body: "teatasedfasdf\n", created_at: "2014-04-20 22:12:40", updated_at: "2014-04-20 22:12:40", token: "8yE5HGJLv5jqOr4azEDxHQ">
按令牌搜索记录(FAILS):
2.1.1 :022 > m = Message.where(token: '8yE5HGJLv5jqOr4azEDxHQ').first
Message Load (0.7ms) SELECT `messages`.* FROM `messages` WHERE `messages`.`token` = '8yE5HGJLv5jqOr4azEDxHQ' ORDER BY `messages`.`id` ASC LIMIT 1
=> nil
此外,我注意到失败的一个是“消息存在”动作,而另一个则没有。
为什么第二个“where”动作不能找到令牌但第一个可以?