I am using Ruby on Rails 3.0.7 and I would like to know, regarding performance matters, what are differences between the User.find(<id>)
method and the User.where(:id => <id>)
method.
Under the hood, find
does more or less what you're describing with your where
. You can find the details in this post. That being said, if you're looking to grab a single record by id, then you might want to use find_one
. That's what find
winds up doing when you call it with a single argument of an id, but you'll skip past all the other code it needs to run to figure out that's what you wanted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With