使用rails exists?
方法时,我有点挣扎。实际上,我正在尝试检查是否存在Location
和longitude
的{{1}}。我的代码看起来像这样
latitude
现在,即使存在具有此确切数据的对象,也始终返回false。
使用时
Location.exists?(longitude: 9.81639, latitude: 52.4003)
Location Exists (0.3ms) SELECT 1 AS one FROM `locations` WHERE `locations`.`longitude` = 9.81639 AND `locations`.`latitude` = 52.4003 LIMIT 1
=> false
我得到以下输出,一切正常。我得到了理想的结果。
Location.exists?(country: "Germany")
我无法弄清楚我做错了什么。
编辑:一些额外的输出
Location.where(country: "Germany").first.attributes
Location Load (0.4ms) SELECT `locations`.* FROM `locations` WHERE `locations`.`country` = 'Germany' ORDER BY `locations`.`id` ASC LIMIT 1
{"id"=>1, "spot_id"=>nil, "street"=>"Garbeweg 2", "zip"=>"30655", "city"=>"Hanover", "country"=>"Germany", "longitude"=>9.81639, "latitude"=>52.4003, "created_at"=>Wed, 09 Jul 2014 13:08:48 UTC +00:00, "updated_at"=>Wed, 09 Jul 2014 13:08:48 UTC +00:00}
手动检查相等性时,我得到了:
Location.where(longitude: 9.81639, latitude: 52.4003).first
Location Load (0.3ms) SELECT `locations`.* FROM `locations` WHERE `locations`.`longitude` = 9.81639 AND `locations`.`latitude` = 52.4003 ORDER BY `locations`.`id` ASC LIMIT 1
=> nil