aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAngelo Capilleri <capilleri@yahoo.com>2012-09-29 23:29:48 +0200
committerAngelo Capilleri <capilleri@yahoo.com>2012-09-29 23:37:23 +0200
commitf224b4f083963ef5148d93a4007c428e17ac5233 (patch)
tree735a9a1e8d99e1ac330932eeb2f94ca77fb9792a /activerecord
parentf655108c260ccd334e494b7d6da8822b31cc2156 (diff)
downloadrails-f224b4f083963ef5148d93a4007c428e17ac5233.tar.gz
rails-f224b4f083963ef5148d93a4007c428e17ac5233.tar.bz2
rails-f224b4f083963ef5148d93a4007c428e17ac5233.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb8
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?