aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-18 07:23:38 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-01-11 17:32:48 +0900
commiteb5fef554fde84d36b45191182ed98bd344dc967 (patch)
tree9f8b83bee569bcd8a75c093748d73e46cf488417 /activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
parent235eb91bad58ab18b45aa36fa3a1ebedfe1c4879 (diff)
downloadrails-eb5fef554fde84d36b45191182ed98bd344dc967.tar.gz
rails-eb5fef554fde84d36b45191182ed98bd344dc967.tar.bz2
rails-eb5fef554fde84d36b45191182ed98bd344dc967.zip
Refactor `build_relation` in the uniqueness validator to avoid low level predicate construction
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 346d4b067a..0d2d66f919 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -504,15 +504,17 @@ module ActiveRecord
@connection
end
- def case_sensitive_comparison(table, attribute, column, value) # :nodoc:
- table[attribute].eq(value)
+ def case_sensitive_comparison(attribute, value) # :nodoc:
+ attribute.eq(value)
end
- def case_insensitive_comparison(table, attribute, column, value) # :nodoc:
+ def case_insensitive_comparison(attribute, value) # :nodoc:
+ column = column_for_attribute(attribute)
+
if can_perform_case_insensitive_comparison_for?(column)
- table[attribute].lower.eq(table.lower(value))
+ attribute.lower.eq(attribute.relation.lower(value))
else
- table[attribute].eq(value)
+ attribute.eq(value)
end
end
@@ -659,6 +661,11 @@ module ActiveRecord
raise(ActiveRecordError, "No such column: #{table_name}.#{column_name}")
end
+ def column_for_attribute(attribute)
+ table_name = attribute.relation.name
+ schema_cache.columns_hash(table_name)[attribute.name.to_s]
+ end
+
def collector
if prepared_statements
Arel::Collectors::Composite.new(