diff options
author | Matthew Draper <matthew@trebex.net> | 2016-11-27 23:12:31 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-27 23:12:31 +1030 |
commit | 747ddd34abf34c32b04fd4ef83ed6754f4455b55 (patch) | |
tree | 6bfd9b08508ac708bdea72aefd154c27df3c0d2d /activerecord/lib | |
parent | c42daff32da8e75c684ba485df1d9e3868121ff3 (diff) | |
parent | 8a0fda63aa6ab9b5c30cb23a1c3f5a3399d703f8 (diff) | |
download | rails-747ddd34abf34c32b04fd4ef83ed6754f4455b55.tar.gz rails-747ddd34abf34c32b04fd4ef83ed6754f4455b55.tar.bz2 rails-747ddd34abf34c32b04fd4ef83ed6754f4455b55.zip |
Merge pull request #26865 from sergey-alekseev/uniqueness-validation-scope-with-polymorphic-association
fix the uniqueness validation scope with a polymorphic association
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/validations/uniqueness.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index bed93bfc26..512fdadacc 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -85,11 +85,10 @@ module ActiveRecord def scope_relation(record, relation) Array(options[:scope]).each do |scope_item| - if reflection = record.class._reflect_on_association(scope_item) - scope_value = record.send(reflection.foreign_key) - scope_item = reflection.foreign_key + scope_value = if record.class._reflect_on_association(scope_item) + record.association(scope_item).reader else - scope_value = record._read_attribute(scope_item) + record._read_attribute(scope_item) end relation = relation.where(scope_item => scope_value) end |