Skip to content

Commit f48d271

Browse files
committed
Merge pull request rails#23803 from kamipo/reduce_attribute_to_s
Reduce `attribute.to_s`
2 parents e8d58bb + 8a4c328 commit f48d271

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

activerecord/lib/active_record/validations/uniqueness.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ def build_relation(klass, table, attribute, value) #:nodoc:
5757
value = value.attributes[reflection.klass.primary_key] unless value.nil?
5858
end
5959

60-
attribute_name = attribute.to_s
61-
6260
# the attribute may be an aliased attribute
63-
if klass.attribute_aliases[attribute_name]
64-
attribute = klass.attribute_aliases[attribute_name]
65-
attribute_name = attribute.to_s
61+
if klass.attribute_alias?(attribute)
62+
attribute = klass.attribute_alias(attribute)
6663
end
6764

65+
attribute_name = attribute.to_s
66+
6867
column = klass.columns_hash[attribute_name]
6968
cast_type = klass.type_for_attribute(attribute_name)
7069
value = cast_type.serialize(value)
@@ -82,7 +81,7 @@ def build_relation(klass, table, attribute, value) #:nodoc:
8281
if value.nil?
8382
klass.unscoped.where(comparison)
8483
else
85-
bind = Relation::QueryAttribute.new(attribute.to_s, value, Type::Value.new)
84+
bind = Relation::QueryAttribute.new(attribute_name, value, Type::Value.new)
8685
klass.unscoped.where(comparison, bind)
8786
end
8887
rescue RangeError

0 commit comments

Comments
 (0)