Under the hood: ActiveRecord::Base.find, Part 1
Posted by Jamis on November 17, 2006 @ 03:55 PM
People attribute a lot of magic behavior to
ActiveRecord::Base.find, and rightly so. It does a lot of different things. Want to find a record by id? Done. Multiple records by id? Done. Records based on custom conditions, including associations (arbitrarily deep), and limit the result? Done, done, and done.
However, all this magic comes at a price: the implementation of
find is non-trivial.
I’d like to help people better understand how
find works. By understanding what it does and how it does it, you’ll be able to make better decisions about your own applications, such as when eager loading of associations might be a bad idea, or what kinds of indexes your tables need.
So, next week (Thanksgiving notwithstanding) I’ll work on getting the first installment out. I learned one very important thing from the last “Under the hood” series I did: don’t write monstrously long articles, because most people won’t read them. So, this series will consist of much shorter, more bite-sized looks at specific parts of the #find implementation. Stay tuned!