Permalink
Browse files

Remove deprecated `sanitize_sql_hash_for_conditions`

  • Loading branch information...
rafaelfranca committed Jan 4, 2015
1 parent ede8c19 commit 3a59dd212315ebb9bae8338b98af259ac00bbef3
@@ -1,3 +1,7 @@
+* Remove deprecated `sanitize_sql_hash_for_conditions`.
+
+ *Rafael Mendonça França*
+
* Remove deprecated `Reflection#source_macro`.
*Rafael Mendonça França*
@@ -72,35 +72,6 @@ def expand_hash_conditions_for_aggregates(attrs)
expanded_attrs
end
- # Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE clause.
- # { name: "foo'bar", group_id: 4 }
- # # => "name='foo''bar' and group_id= 4"
- # { status: nil, group_id: [1,2,3] }
- # # => "status IS NULL and group_id IN (1,2,3)"
- # { age: 13..18 }
- # # => "age BETWEEN 13 AND 18"
- # { 'other_records.id' => 7 }
- # # => "`other_records`.`id` = 7"
- # { other_records: { id: 7 } }
- # # => "`other_records`.`id` = 7"
- # And for value objects on a composed_of relationship:
- # { 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)
- table = Arel::Table.new(table_name).alias(default_table_name)
- predicate_builder = PredicateBuilder.new(TableMetadata.new(self, table))
- ActiveSupport::Deprecation.warn(<<-EOWARN)
-sanitize_sql_hash_for_conditions is deprecated, and will be removed in Rails 5.0
- EOWARN
- attrs = predicate_builder.resolve_column_aliases(attrs)
- attrs = expand_hash_conditions_for_aggregates(attrs)
-
- predicate_builder.build_from_hash(attrs).map { |b|
- connection.visitor.compile b
- }.join(' AND ')
- end
- alias_method :sanitize_sql_hash, :sanitize_sql_hash_for_conditions
-
# Sanitizes a hash of attribute/value pairs into SQL conditions for a SET clause.
# { status: nil, group_id: 1 }
# # => "status = NULL , group_id = 1"
@@ -7,17 +7,6 @@ class SanitizeTest < ActiveRecord::TestCase
def setup
end
- def test_sanitize_sql_hash_handles_associations
- quoted_bambi = ActiveRecord::Base.connection.quote("Bambi")
- quoted_column_name = ActiveRecord::Base.connection.quote_column_name("name")
- quoted_table_name = ActiveRecord::Base.connection.quote_table_name("adorable_animals")
- expected_value = "#{quoted_table_name}.#{quoted_column_name} = #{quoted_bambi}"
-
- assert_deprecated do
- assert_equal expected_value, Binary.send(:sanitize_sql_hash, {adorable_animals: {name: 'Bambi'}})
- end
- end
-
def test_sanitize_sql_array_handles_string_interpolation
quoted_bambi = ActiveRecord::Base.connection.quote_string("Bambi")
assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=%s", "Bambi"])

3 comments on commit 3a59dd2

@matthewrudy

This comment has been minimized.

Show comment
Hide comment
@matthewrudy

matthewrudy May 12, 2015

Contributor

This removed the code,
but sanitize_sql_hash_for_conditions is still called inside sanitize_conditions as of master.

Contributor

matthewrudy replied May 12, 2015

This removed the code,
but sanitize_sql_hash_for_conditions is still called inside sanitize_conditions as of master.

@matthewrudy

This comment has been minimized.

Show comment
Hide comment
@matthewrudy

matthewrudy May 12, 2015

Contributor

Also, I think this was a really useful method.
And it seems everyone is now having to hack around it to achieve the same result.

https://github.com/CanCanCommunity/cancancan/blob/7393b94ca1788879b7ba968c9fb3c6df3806f678/lib/cancan/model_adapters/active_record_4_adapter.rb#L22-L35

Contributor

matthewrudy replied May 12, 2015

Also, I think this was a really useful method.
And it seems everyone is now having to hack around it to achieve the same result.

https://github.com/CanCanCommunity/cancancan/blob/7393b94ca1788879b7ba968c9fb3c6df3806f678/lib/cancan/model_adapters/active_record_4_adapter.rb#L22-L35

@matthewrudy

This comment has been minimized.

Show comment
Hide comment
@matthewrudy

matthewrudy May 12, 2015

Contributor

I issued a PR to remove the remaining call to the method.
#20121

Contributor

matthewrudy replied May 12, 2015

I issued a PR to remove the remaining call to the method.
#20121

Please sign in to comment.