Permalink
Browse files

Merge pull request #7947 from acapilleri/uniqueness_validate

refactoring of uniqueness validate_each
  • Loading branch information...
2 parents ae61c03 + 08927cf commit a550a6839a256a9504b2dfc0eba949e36e39c061 @rafaelfranca rafaelfranca committed Oct 14, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 activerecord/lib/active_record/validations/uniqueness.rb
@@ -26,11 +26,12 @@ def validate_each(record, attribute, value)
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

0 comments on commit a550a68

Please sign in to comment.