Skip to content

Commit 3a59dd2

Browse files
committed
Remove deprecated sanitize_sql_hash_for_conditions
1 parent ede8c19 commit 3a59dd2

File tree

3 files changed

+4
-40
lines changed

3 files changed

+4
-40
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated `sanitize_sql_hash_for_conditions`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated `Reflection#source_macro`.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/sanitization.rb

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,6 @@ def expand_hash_conditions_for_aggregates(attrs)
7272
expanded_attrs
7373
end
7474

75-
# Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE clause.
76-
# { name: "foo'bar", group_id: 4 }
77-
# # => "name='foo''bar' and group_id= 4"
78-
# { status: nil, group_id: [1,2,3] }
79-
# # => "status IS NULL and group_id IN (1,2,3)"
80-
# { age: 13..18 }
81-
# # => "age BETWEEN 13 AND 18"
82-
# { 'other_records.id' => 7 }
83-
# # => "`other_records`.`id` = 7"
84-
# { other_records: { id: 7 } }
85-
# # => "`other_records`.`id` = 7"
86-
# And for value objects on a composed_of relationship:
87-
# { address: Address.new("123 abc st.", "chicago") }
88-
# # => "address_street='123 abc st.' and address_city='chicago'"
89-
def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
90-
table = Arel::Table.new(table_name).alias(default_table_name)
91-
predicate_builder = PredicateBuilder.new(TableMetadata.new(self, table))
92-
ActiveSupport::Deprecation.warn(<<-EOWARN)
93-
sanitize_sql_hash_for_conditions is deprecated, and will be removed in Rails 5.0
94-
EOWARN
95-
attrs = predicate_builder.resolve_column_aliases(attrs)
96-
attrs = expand_hash_conditions_for_aggregates(attrs)
97-
98-
predicate_builder.build_from_hash(attrs).map { |b|
99-
connection.visitor.compile b
100-
}.join(' AND ')
101-
end
102-
alias_method :sanitize_sql_hash, :sanitize_sql_hash_for_conditions
103-
10475
# Sanitizes a hash of attribute/value pairs into SQL conditions for a SET clause.
10576
# { status: nil, group_id: 1 }
10677
# # => "status = NULL , group_id = 1"

activerecord/test/cases/sanitize_test.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ class SanitizeTest < ActiveRecord::TestCase
77
def setup
88
end
99

10-
def test_sanitize_sql_hash_handles_associations
11-
quoted_bambi = ActiveRecord::Base.connection.quote("Bambi")
12-
quoted_column_name = ActiveRecord::Base.connection.quote_column_name("name")
13-
quoted_table_name = ActiveRecord::Base.connection.quote_table_name("adorable_animals")
14-
expected_value = "#{quoted_table_name}.#{quoted_column_name} = #{quoted_bambi}"
15-
16-
assert_deprecated do
17-
assert_equal expected_value, Binary.send(:sanitize_sql_hash, {adorable_animals: {name: 'Bambi'}})
18-
end
19-
end
20-
2110
def test_sanitize_sql_array_handles_string_interpolation
2211
quoted_bambi = ActiveRecord::Base.connection.quote_string("Bambi")
2312
assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=%s", "Bambi"])

0 commit comments

Comments
 (0)