rails/rails — pull request #4216 by al2o3cr (2011-12-28 14:56:15+00:00)
Title: allow reorder to affect eager loading correctly

(master-based version of https://github.com/rails/rails/pull/4082)

Calling `last` on an association that's scoped with `reorder` can cause some adapters to fail (particularly oracle_enhanced and postgres). The underlying cause is that `connection.distinct` expects the desired order, but the relation's `reorder_values` are not passed along, since `construct_limited_ids` explicitly grabs `order_values`.

See the attached commit for additional details - this bug does not affect the mysql or sqlite adapters, as those use the default order-agnostic implementation of `distinct`.