Performance differences between the .find and .where methods

I am using Ruby on Rails 3.0.7, and I would like to know regarding performance, what are the differences between the User.find(<id>)and method User.where(:id => <id>).

+5
source share
2 answers

Under the hood finddoes more or less what you describe with where. You can find the details in this post . At the same time, if you want to capture one record by id, you can use find_one. What findends when you call it with a single id argument, but you will skip all the other codes that you need to execute to figure out what you wanted.

+1
source

The short answer is, but: It really doesn't matter (unless you have a unique constraint in the column id).

+1
source

All Articles