We have support for first/last methods on a model class:
Project.first
Project.last(:order => 'name')
Wouldn't it be nice if this worked on association proxies as well? If a category has many products it would work like this:
category.products.first
category.products.last(:order => 'name')
While we're at it, let's make it work for named_scope too. Say we have a "recent" named scope, we can quickly fetch the first or last recent product like this:
Product.recent.first
category.products.recent.last
The attached patch will add the first/last methods to both the association proxy and scopes. Tests are included.
Note: I needed to change a couple of existing tests to get this to work because they relied on first/last loading the association target. However this was not the functionality being tested so I think it's acceptable.