diff options
author | Sergey Alekseev <sergey.alekseev.minsk@gmail.com> | 2016-11-26 15:17:11 +0300 |
---|---|---|
committer | Sergey Alekseev <sergey.alekseev.minsk@gmail.com> | 2016-11-26 18:49:00 +0300 |
commit | 8a0fda63aa6ab9b5c30cb23a1c3f5a3399d703f8 (patch) | |
tree | e5adb09c024e8e1103fd5cc3e9eb920a52c7a28c /activerecord/lib/active_record/validations | |
parent | ebdf87a0bd6efc2f441a39517625af1a4d921496 (diff) | |
download | rails-8a0fda63aa6ab9b5c30cb23a1c3f5a3399d703f8.tar.gz rails-8a0fda63aa6ab9b5c30cb23a1c3f5a3399d703f8.tar.bz2 rails-8a0fda63aa6ab9b5c30cb23a1c3f5a3399d703f8.zip |
fix the uniqueness validation scope with a polymorphic association
https://gist.github.com/sergey-alekseev/946657ebdb5e58d1bee115714056ec96
Diffstat (limited to 'activerecord/lib/active_record/validations')
-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 |