Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e4d064c6
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4d064c6
编写于
7月 02, 2013
作者:
C
Carlos Antonio da Silva
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11255 from neerajdotname/restrict-be-gone
Dropped deprecated option `:restrict` for `:dependent` in associations
上级
a95cbabc
0e370036
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
9 addition
and
49 deletion
+9
-49
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/associations/builder/association.rb
...ord/lib/active_record/associations/builder/association.rb
+0
-7
activerecord/lib/active_record/associations/builder/has_many.rb
...record/lib/active_record/associations/builder/has_many.rb
+1
-1
activerecord/lib/active_record/associations/builder/has_one.rb
...erecord/lib/active_record/associations/builder/has_one.rb
+1
-1
activerecord/lib/active_record/associations/has_many_association.rb
...rd/lib/active_record/associations/has_many_association.rb
+1
-1
activerecord/lib/active_record/associations/has_one_association.rb
...ord/lib/active_record/associations/has_one_association.rb
+1
-1
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+0
-15
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+0
-16
activerecord/test/models/company.rb
activerecord/test/models/company.rb
+0
-7
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
e4d064c6
*
Removed support for deprecated option
`:restrict`
for
`:dependent`
in associations.
*Neeraj Singh*
*
Removed support for deprecated
`delete_sql`
in associations.
*Neeraj Singh*
...
...
activerecord/lib/active_record/associations/builder/association.rb
浏览文件 @
e4d064c6
...
...
@@ -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
...
...
activerecord/lib/active_record/associations/builder/has_many.rb
浏览文件 @
e4d064c6
...
...
@@ -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
activerecord/lib/active_record/associations/builder/has_one.rb
浏览文件 @
e4d064c6
...
...
@@ -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
activerecord/lib/active_record/associations/has_many_association.rb
浏览文件 @
e4d064c6
...
...
@@ -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
...
...
activerecord/lib/active_record/associations/has_one_association.rb
浏览文件 @
e4d064c6
...
...
@@ -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
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
e4d064c6
...
...
@@ -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'
)
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
e4d064c6
...
...
@@ -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
)
...
...
activerecord/test/models/company.rb
浏览文件 @
e4d064c6
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录