Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7791 from acapilleri/build_association

small refactoring of build_relation in uniqueness
  • Loading branch information...
commit 15712ac4c98a34f5f465ffcb2374737d94bb9081 2 parents 623f2fb + f224b4f
@rafaelfranca rafaelfranca authored
Showing with 3 additions and 5 deletions.
  1. +3 −5 activerecord/lib/active_record/validations/uniqueness.rb
View
8 activerecord/lib/active_record/validations/uniqueness.rb
@@ -64,14 +64,12 @@ def find_finder_class_for(record) #:nodoc:
end
def build_relation(klass, table, attribute, value) #:nodoc:
- reflection = klass.reflect_on_association(attribute)
- if reflection
- column = klass.columns_hash[reflection.foreign_key]
+ if reflection = klass.reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.primary_key_column.name]
- else
- column = klass.columns_hash[attribute.to_s]
end
+
+ column = klass.columns_hash[attribute.to_s]
value = column.limit ? value.to_s[0, column.limit] : value.to_s if !value.nil? && column.text?
if !options[:case_sensitive] && value && column.text?
Please sign in to comment.
Something went wrong with that request. Please try again.