rails/rails — pull request #5264 by jtcalhoun (2012-03-04 01:26:35+00:00)
Title: use read_attribute to allow scoping by an aggregation's attribute value

The following error is produced in `Arel` when an aggregation is provided as the `:scope` parameter to `validates_uniqueness_of`:

```
TypeError: Cannot visit CustomClassWithoutRecognizedAncestors
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:25:in `rescue in visit'
from /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/arel-3.0.2/lib/arel/visitors/visitor.rb:19:in `visit'
...
```

`ActiveRecord` uses the aggregation's value object as the scope value instead of its actual attribute value.

The attached code resolves this issue by using the attribute value after type cast but before conversion.