Reputation: 15259
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.
Upvotes: 5
Views: 2372
Reputation: 16262
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.
Upvotes: 1
Reputation: 54752
Short answer, but: It really doesn't matter (unless you don't have a unique-constraint on your id
column).
Upvotes: 1