提交 d9fca84d 编写于 作者: R Ryuta Kamizono

Deprecate delegating to `arel` in `Relation`

Active Record doesn't rely delegating to `arel` in the internal since
425f2cac. The delegation is a lower priority than delegating to `klass`,
so it is pretty unclear which method is delegated to `arel`.

For example, `bind_values` method was removed at b06f64c3 (a series of
changes https://github.com/rails/rails/compare/79f71d3...b06f64c). But a
relation still could respond to the method because `arel` also have the
same named method (#28976).

Removing the delegation will achieve predictable behavior.
上级 4448873c
* Deprecate delegating to `arel` in `Relation`.
*Ryuta Kamizono*
* Fix eager loading to respect `store_full_sti_class` setting.
*Ryuta Kamizono*
......
......@@ -89,6 +89,8 @@ def method_missing(method, *args, &block)
self.class.delegate_to_scoped_klass(method)
scoping { @klass.public_send(method, *args, &block) }
elsif arel.respond_to?(method)
ActiveSupport::Deprecation.warn \
"Delegating #{method} to arel is deprecated and will be removed in Rails 6.0."
self.class.delegate method, to: :arel
arel.public_send(method, *args, &block)
else
......
......@@ -21,8 +21,22 @@ module DelegationWhitelistTests
end
end
module DeprecatedArelDelegationTests
AREL_METHODS = [
:with, :orders, :froms, :project, :projections, :taken, :constraints, :exists, :locked, :where_sql,
:ast, :source, :join_sources, :to_dot, :bind_values, :create_insert, :create_true, :create_false
]
def test_deprecate_arel_delegation
AREL_METHODS.each do |method|
assert_deprecated { target.public_send(method) }
end
end
end
class DelegationAssociationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
include DeprecatedArelDelegationTests
fixtures :posts
......@@ -33,6 +47,7 @@ def target
class DelegationRelationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
include DeprecatedArelDelegationTests
fixtures :comments
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册