提交 e4d064c6 编写于 作者: C Carlos Antonio da Silva

Merge pull request #11255 from neerajdotname/restrict-be-gone

Dropped deprecated option `:restrict` for `:dependent` in associations
* Removed support for deprecated option `:restrict` for `:dependent`
in associations.
*Neeraj Singh*
* Removed support for deprecated `delete_sql` in associations.
*Neeraj Singh*
......
......@@ -104,13 +104,6 @@ def configure_dependency
raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{options[:dependent]}"
end
if options[:dependent] == :restrict
ActiveSupport::Deprecation.warn(
"The :restrict option is deprecated. Please use :restrict_with_exception instead, which " \
"provides the same functionality."
)
end
n = name
model.before_destroy lambda { |o| o.association(n).handle_dependency }
end
......
......@@ -9,7 +9,7 @@ def valid_options
end
def valid_dependent_options
[:destroy, :delete_all, :nullify, :restrict, :restrict_with_error, :restrict_with_exception]
[:destroy, :delete_all, :nullify, :restrict_with_error, :restrict_with_exception]
end
end
end
......@@ -19,7 +19,7 @@ def configure_dependency
end
def valid_dependent_options
[:destroy, :delete, :nullify, :restrict, :restrict_with_error, :restrict_with_exception]
[:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception]
end
end
end
......@@ -9,7 +9,7 @@ class HasManyAssociation < CollectionAssociation #:nodoc:
def handle_dependency
case options[:dependent]
when :restrict, :restrict_with_exception
when :restrict_with_exception
raise ActiveRecord::DeleteRestrictionError.new(reflection.name) unless empty?
when :restrict_with_error
......
......@@ -6,7 +6,7 @@ class HasOneAssociation < SingularAssociation #:nodoc:
def handle_dependency
case options[:dependent]
when :restrict, :restrict_with_exception
when :restrict_with_exception
raise ActiveRecord::DeleteRestrictionError.new(reflection.name) if load_target
when :restrict_with_error
......
......@@ -1092,21 +1092,6 @@ def test_depends_and_nullify
assert_equal num_accounts, Account.count
end
def test_restrict
firm = RestrictedFirm.create!(:name => 'restrict')
firm.companies.create(:name => 'child')
assert !firm.companies.empty?
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
assert RestrictedFirm.exists?(:name => 'restrict')
assert firm.companies.exists?(:name => 'child')
end
def test_restrict_is_deprecated
klass = Class.new(ActiveRecord::Base)
assert_deprecated { klass.has_many :posts, dependent: :restrict }
end
def test_restrict_with_exception
firm = RestrictedWithExceptionFirm.create!(:name => 'restrict')
firm.companies.create(:name => 'child')
......
......@@ -158,22 +158,6 @@ def test_dependence_with_nil_associate
assert_nothing_raised { firm.destroy }
end
def test_restrict
firm = RestrictedFirm.create!(:name => 'restrict')
firm.create_account(:credit_limit => 10)
assert_not_nil firm.account
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
assert RestrictedFirm.exists?(:name => 'restrict')
assert firm.account.present?
end
def test_restrict_is_deprecated
klass = Class.new(ActiveRecord::Base)
assert_deprecated { klass.has_one :post, dependent: :restrict }
end
def test_restrict_with_exception
firm = RestrictedWithExceptionFirm.create!(:name => 'restrict')
firm.create_account(:credit_limit => 10)
......
......@@ -95,13 +95,6 @@ class DependentFirm < Company
has_one :company, :foreign_key => 'client_of', :dependent => :nullify
end
class RestrictedFirm < Company
ActiveSupport::Deprecation.silence do
has_one :account, -> { order("id") }, :foreign_key => "firm_id", :dependent => :restrict
has_many :companies, -> { order("id") }, :foreign_key => 'client_of', :dependent => :restrict
end
end
class RestrictedWithExceptionFirm < Company
has_one :account, -> { order("id") }, :foreign_key => "firm_id", :dependent => :restrict_with_exception
has_many :companies, -> { order("id") }, :foreign_key => 'client_of', :dependent => :restrict_with_exception
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册