diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-29 21:20:59 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-29 21:20:59 -0700 |
commit | 15712ac4c98a34f5f465ffcb2374737d94bb9081 (patch) | |
tree | e9953c4f225a98b8a0dce40793a666f4953b6255 | |
parent | 623f2fbb933994bb81187c18984ae51047d9b029 (diff) | |
parent | f224b4f083963ef5148d93a4007c428e17ac5233 (diff) | |
download | rails-15712ac4c98a34f5f465ffcb2374737d94bb9081.tar.gz rails-15712ac4c98a34f5f465ffcb2374737d94bb9081.tar.bz2 rails-15712ac4c98a34f5f465ffcb2374737d94bb9081.zip |
Merge pull request #7791 from acapilleri/build_association
small refactoring of build_relation in uniqueness
-rw-r--r-- | activerecord/lib/active_record/validations/uniqueness.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index f3620c1324..5dece1cb36 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -64,14 +64,12 @@ module ActiveRecord 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? |