rails/rails — pull request #8094 by al2o3cr (2012-11-01 15:19:48+00:00)
Title: set inverses correctly for first(n) and last(n)

The code introduced in #7377 assumes that `first` and `last` always return a single record. This is incorrect for calling `first` with an integer argument.

The attached commit (against 3-2-stable) handles this case correctly and includes a test.

I'm not super-happy with the resulting code; there's way too much `is_a?` checking going on in `first_or_last`, but this will work for now to get 3.2.9 out.