mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #7947 from acapilleri/uniqueness_validate
refactoring of uniqueness validate_each
This commit is contained in:
commit
a550a6839a
1 changed files with 2 additions and 1 deletions
|
@ -26,11 +26,12 @@ module ActiveRecord
|
|||
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
|
||||
|
||||
Array(options[:scope]).each do |scope_item|
|
||||
scope_value = record.read_attribute(scope_item)
|
||||
reflection = record.class.reflect_on_association(scope_item)
|
||||
if reflection
|
||||
scope_value = record.send(reflection.foreign_key)
|
||||
scope_item = reflection.foreign_key
|
||||
else
|
||||
scope_value = record.read_attribute(scope_item)
|
||||
end
|
||||
relation = relation.and(table[scope_item].eq(scope_value))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue