Lighthouse W3D3 – #42

Today I learned about some of ActiveRecord’s FinderMethods. I was playing around with my database finding student records. I used first, then tried second, and third… they all worked! I was curious so I tried more, unfortunately there’s no sixth method to find the sixth record. It’s important to note that first does not mean find the record with id of “1”, it just means the first record in the database.

Student.first is the same as SELECT * FROM students ORDER BY students.id LIMIT 1.

If you look at the documentation, you’ll see that there’s a forty_two method, to retrieve the forty second record in the database. Yes, it’s a reference to the Hitchhiker’s Guide to the Galaxy!!! 42, or  “The Answer to the Ultimate Question of Life, the Universe, and Everything”.

And carry a towel.
And carry a towel.

If you want to read the commits and drama:

Part 1: Where DHH adds helper methods from second to tenth. (Check out the comments below!)

Part 2: Where DHH responds to the comments by removing the methods sixth to tenth, and adding forty_two.

Niceeee.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s