From eb921000a11bc87a3b001164fc367b84aee584c5 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 2 Nov 2014 13:34:52 -0700 Subject: [PATCH] Deprecate `sanitize_sql_hash_` methods on ActiveRecord These appear to be implementation relics of times past. They duplicate the logic in Relation, and are no longer used internally. --- activerecord/CHANGELOG.md | 6 ++++++ activerecord/lib/active_record/sanitization.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index ab85f2a472..5404465b4c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* Deprecate `sanitize_sql_hash_for_conditions` and + `sanitize_sql_hash_for_assignment` without replacement. Using a `Relation` + for performing queries and updates is the prefered API. + + *Sean Griffin* + * Queries now properly type cast values that are part of a join statement, even when using type decorators such as `serialize`. diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 2c5cf944a4..d80b516c67 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -87,6 +87,9 @@ def expand_hash_conditions_for_aggregates(attrs) # { address: Address.new("123 abc st.", "chicago") } # # => "address_street='123 abc st.' and address_city='chicago'" def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name) + ActiveSupport::Deprecation.warn(<<-EOWARN) +sanitize_sql_hash_for_conditions is deprecated, and will be removed in Rails 5.0 + EOWARN attrs = PredicateBuilder.resolve_column_aliases self, attrs attrs = expand_hash_conditions_for_aggregates(attrs) @@ -101,6 +104,9 @@ def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name # { status: nil, group_id: 1 } # # => "status = NULL , group_id = 1" def sanitize_sql_hash_for_assignment(attrs, table) + ActiveSupport::Deprecation.warn(<<-EOWARN) +sanitize_sql_hash_for_assignment is deprecated, and will be removed in Rails 5.0 + EOWARN c = connection attrs.map do |attr, value| "#{c.quote_table_name_for_assignment(table, attr)} = #{quote_bound_value(value, c, columns_hash[attr.to_s])}" -- GitLab