Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance differences between '.find' and '.where' methods

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.

like image 750
user502052 Avatar asked Nov 04 '22 19:11

user502052


1 Answers

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.

like image 119
RHSeeger Avatar answered Nov 09 '22 14:11

RHSeeger