1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove deprecated support to pass a column to type_cast

This commit is contained in:
Rafael Mendonça França 2021-11-17 21:20:21 +00:00
parent 21c8e5c4ee
commit 2d821ef0c5
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
5 changed files with 12 additions and 56 deletions

View file

@ -1,3 +1,7 @@
* Remove deprecated support to pass a column to `type_cast`.
*Rafael Mendonça França*
* Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
*Rafael Mendonça França*

View file

@ -15,15 +15,7 @@ module ActiveRecord
# Cast a +value+ to a type that the database understands. For example,
# SQLite does not understand dates, so this method will convert a Date
# to a String.
def type_cast(value, column = nil)
if column
ActiveSupport::Deprecation.warn(<<~MSG)
Passing a column to `type_cast` is deprecated and will be removed in Rails 7.0.
MSG
type = lookup_cast_type_from_column(column)
value = type.serialize(value)
end
def type_cast(value)
_type_cast(value)
end
@ -187,16 +179,11 @@ module ActiveRecord
private
def type_casted_binds(binds)
case binds.first
when Array
binds.map { |column, value| type_cast(value, column) }
else
binds.map do |value|
if ActiveModel::Attribute === value
type_cast(value.value_for_database)
else
type_cast(value)
end
binds.map do |value|
if ActiveModel::Attribute === value
type_cast(value.value_for_database)
else
type_cast(value)
end
end
end

View file

@ -237,36 +237,6 @@ module ActiveRecord
end
if ActiveRecord::Base.connection.prepared_statements
def test_select_all_insert_update_delete_with_legacy_binds
binds = [[Event.column_for_attribute("id"), 1]]
bind_param = Arel::Nodes::BindParam.new(nil)
assert_deprecated do
id = @connection.insert("INSERT INTO events(id) VALUES (#{bind_param.to_sql})", nil, nil, nil, nil, binds)
assert_equal 1, id
end
assert_deprecated do
updated = @connection.update("UPDATE events SET title = 'foo' WHERE id = #{bind_param.to_sql}", nil, binds)
assert_equal 1, updated
end
assert_deprecated do
result = @connection.select_all("SELECT * FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
assert_equal({ "id" => 1, "title" => "foo" }, result.first)
end
assert_deprecated do
deleted = @connection.delete("DELETE FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
assert_equal 1, deleted
end
assert_deprecated do
result = @connection.select_all("SELECT * FROM events WHERE id = #{bind_param.to_sql}", nil, binds)
assert_nil result.first
end
end
def test_select_all_insert_update_delete_with_casted_binds
binds = [Event.type_for_attribute("id").serialize(1)]
bind_param = Arel::Nodes::BindParam.new(nil)

View file

@ -156,13 +156,6 @@ if ActiveRecord::Base.connection.prepared_statements
assert_logs_binds(binds)
end
def test_logs_legacy_binds_after_type_cast
binds = [[Topic.column_for_attribute("id"), "10"]]
assert_deprecated do
assert_logs_binds(binds)
end
end
def test_bind_params_to_sql_with_prepared_statements
assert_bind_params_to_sql
end

View file

@ -122,6 +122,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
* Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
* Remove deprecated support to pass a column to `type_cast`.
### Deprecations
### Notable changes