Created
October 29, 2015 15:21
-
-
Save ethangunderson/26e3b0333ff4f55ba148 to your computer and use it in GitHub Desktop.
Friendly reminder that exists?, present? and any? behave differently than what you might expect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):001:0> User.exists? | |
users Columns (20.3ms) SHOW FIELDS FROM `users` | |
User Exists (0.3ms) SELECT 1 AS one FROM `users` LIMIT 1 | |
=> true | |
irb(main):002:0> User.where(:email => "foo").exists? | |
User Exists (0.6ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = 'foo' LIMIT 1 | |
=> false | |
irb(main):003:0> User.where(:email => "foo").present? | |
(0.7ms) SELECT COUNT(*) FROM `users` WHERE `users`.`email` = 'foo' | |
=> false | |
irb(main):004:0> User.where(:email => "foo").any? | |
(0.5ms) SELECT COUNT(*) FROM `users` WHERE `users`.`email` = 'foo' | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment