use read_attribute to allow scoping by an aggregation's attribute value #5264

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@jtcalhoun

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.

Member
drogus commented Mar 4, 2012
Contributor

Is this still an issue?

Owner

Closing this since #6743 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment