From f224b4f083963ef5148d93a4007c428e17ac5233 Mon Sep 17 00:00:00 2001 From: Angelo Capilleri Date: Sat, 29 Sep 2012 23:29:48 +0200 Subject: small refactoring of build_relation in uniqueness reflection init as 'if' stantment. column is always the same expression and depends from the changing of attributes --- activerecord/lib/active_record/validations/uniqueness.rb | 8 +++----- 1 file 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? -- cgit v1.2.3