Skip to content

Commit 2d821ef

Browse files
committed
Remove deprecated support to pass a column to type_cast
1 parent 21c8e5c commit 2d821ef

File tree

5 files changed

+12
-56
lines changed

5 files changed

+12
-56
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 support to pass a column to `type_cast`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ def quote(value)
1515
# Cast a +value+ to a type that the database understands. For example,
1616
# SQLite does not understand dates, so this method will convert a Date
1717
# to a String.
18-
def type_cast(value, column = nil)
19-
if column
20-
ActiveSupport::Deprecation.warn(<<~MSG)
21-
Passing a column to `type_cast` is deprecated and will be removed in Rails 7.0.
22-
MSG
23-
type = lookup_cast_type_from_column(column)
24-
value = type.serialize(value)
25-
end
26-
18+
def type_cast(value)
2719
_type_cast(value)
2820
end
2921

@@ -187,16 +179,11 @@ def column_name_with_order_matcher # :nodoc:
187179

188180
private
189181
def type_casted_binds(binds)
190-
case binds.first
191-
when Array
192-
binds.map { |column, value| type_cast(value, column) }
193-
else
194-
binds.map do |value|
195-
if ActiveModel::Attribute === value
196-
type_cast(value.value_for_database)
197-
else
198-
type_cast(value)
199-
end
182+
binds.map do |value|
183+
if ActiveModel::Attribute === value
184+
type_cast(value.value_for_database)
185+
else
186+
type_cast(value)
200187
end
201188
end
202189
end

activerecord/test/cases/adapter_test.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,36 +237,6 @@ def test_select_all_always_return_activerecord_result
237237
end
238238

239239
if ActiveRecord::Base.connection.prepared_statements
240-
def test_select_all_insert_update_delete_with_legacy_binds
241-
binds = [[Event.column_for_attribute("id"), 1]]
242-
bind_param = Arel::Nodes::BindParam.new(nil)
243-
244-
assert_deprecated do
245-
id = @connection.insert("INSERT INTO events(id) VALUES (#{bind_param.to_sql})", nil, nil, nil, nil, binds)
246-
assert_equal 1, id
247-
end
248-
249-
assert_deprecated do
250-
updated = @connection.update("UPDATE events SET title = 'foo' WHERE id = #{bind_param.to_sql}", nil, binds)
251-
assert_equal 1, updated
252-
end
253-
254-
assert_deprecated do
255-
result = @connection.select_all("SELECT * FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
256-
assert_equal({ "id" => 1, "title" => "foo" }, result.first)
257-
end
258-
259-
assert_deprecated do
260-
deleted = @connection.delete("DELETE FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
261-
assert_equal 1, deleted
262-
end
263-
264-
assert_deprecated do
265-
result = @connection.select_all("SELECT * FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
266-
assert_nil result.first
267-
end
268-
end
269-
270240
def test_select_all_insert_update_delete_with_casted_binds
271241
binds = [Event.type_for_attribute("id").serialize(1)]
272242
bind_param = Arel::Nodes::BindParam.new(nil)

activerecord/test/cases/bind_parameter_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ def test_logs_binds_after_type_cast
156156
assert_logs_binds(binds)
157157
end
158158

159-
def test_logs_legacy_binds_after_type_cast
160-
binds = [[Topic.column_for_attribute("id"), "10"]]
161-
assert_deprecated do
162-
assert_logs_binds(binds)
163-
end
164-
end
165-
166159
def test_bind_params_to_sql_with_prepared_statements
167160
assert_bind_params_to_sql
168161
end

guides/source/7_0_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
122122

123123
* Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
124124

125+
* Remove deprecated support to pass a column to `type_cast`.
126+
125127
### Deprecations
126128

127129
### Notable changes

0 commit comments

Comments
 (0)