ActiveRecord::Base.find :last

written by Jan on March 12th, 2008 @ 11:49 PM

At last! The latest Ruby on Rails changeset has something I’ve always missed.. find :last.

This new functionality adds a whole lot logic for me. For example

Find the last inserted client


Find the last edited subject

  Subject.find(:last, :order => 'modified_at')

This is a lot more readable then

  Subject.find(:first, :order => 'modified_at DESC')

The last code makes me interpret the result of the order, I don’t immediately see what I’m requesting, with the last example I immediatly see I’m taking the last modified subject.

Great stuff! This is the reason I’m on Rails Edge

Comments are closed