Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b17b9371
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,体验更适合开发者的 AI 搜索 >>
提交
b17b9371
编写于
12月 21, 2008
作者:
F
Frederick Cheung
提交者:
Pratik Naik
12月 21, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix configure_dependency_for_has_many not quoting conditions properly [#1461 state:resolved]
上级
6f4b2469
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
3 deletion
+17
-3
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+3
-3
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+13
-0
activerecord/test/models/company.rb
activerecord/test/models/company.rb
+1
-0
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
b17b9371
...
...
@@ -1453,7 +1453,7 @@ def configure_dependency_for_has_many(reflection, extra_conditions = nil)
dependent_conditions
<<
sanitize_sql
(
reflection
.
options
[
:conditions
])
if
reflection
.
options
[
:conditions
]
dependent_conditions
<<
extra_conditions
if
extra_conditions
dependent_conditions
=
dependent_conditions
.
collect
{
|
where
|
"(
#{
where
}
)"
}.
join
(
" AND "
)
dependent_conditions
=
dependent_conditions
.
gsub
(
'@'
,
'\@'
)
case
reflection
.
options
[
:dependent
]
when
:destroy
method_name
=
"has_many_dependent_destroy_for_
#{
reflection
.
name
}
"
.
to_sym
...
...
@@ -1467,7 +1467,7 @@ def configure_dependency_for_has_many(reflection, extra_conditions = nil)
delete_all_has_many_dependencies(record,
"
#{
reflection
.
name
}
",
#{
reflection
.
class_name
}
,
"
#{
dependent_conditions
}
"
)
%@
#{
dependent_conditions
}
@
)
end
}
when
:nullify
...
...
@@ -1477,7 +1477,7 @@ def configure_dependency_for_has_many(reflection, extra_conditions = nil)
"
#{
reflection
.
name
}
",
#{
reflection
.
class_name
}
,
"
#{
reflection
.
primary_key_name
}
",
"
#{
dependent_conditions
}
"
)
%@
#{
dependent_conditions
}
@
)
end
}
else
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
b17b9371
...
...
@@ -665,6 +665,19 @@ def test_dependent_association_respects_optional_sanitized_conditions_on_delete
assert_equal
1
,
Client
.
find_all_by_client_of
(
firm
.
id
).
size
end
def
test_dependent_association_respects_optional_hash_conditions_on_delete
firm
=
companies
(
:odegy
)
Client
.
create
(
:client_of
=>
firm
.
id
,
:name
=>
"BigShot Inc."
)
Client
.
create
(
:client_of
=>
firm
.
id
,
:name
=>
"SmallTime Inc."
)
# only one of two clients is included in the association due to the :conditions key
assert_equal
2
,
Client
.
find_all_by_client_of
(
firm
.
id
).
size
assert_equal
1
,
firm
.
dependent_sanitized_conditional_clients_of_firm
.
size
firm
.
destroy
# only the correctly associated client should have been deleted
assert_equal
1
,
Client
.
find_all_by_client_of
(
firm
.
id
).
size
end
def
test_creation_respects_hash_condition
ms_client
=
companies
(
:first_firm
).
clients_like_ms_with_hash_conditions
.
build
...
...
activerecord/test/models/company.rb
浏览文件 @
b17b9371
...
...
@@ -80,6 +80,7 @@ class ExclusivelyDependentFirm < Company
has_one
:account
,
:foreign_key
=>
"firm_id"
,
:dependent
=>
:delete
has_many
:dependent_sanitized_conditional_clients_of_firm
,
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:order
=>
"id"
,
:dependent
=>
:delete_all
,
:conditions
=>
"name = 'BigShot Inc.'"
has_many
:dependent_conditional_clients_of_firm
,
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:order
=>
"id"
,
:dependent
=>
:delete_all
,
:conditions
=>
[
"name = ?"
,
'BigShot Inc.'
]
has_many
:dependent_hash_conditional_clients_of_firm
,
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:order
=>
"id"
,
:dependent
=>
:delete_all
,
:conditions
=>
{
:name
=>
'BigShot Inc.'
}
end
class
Client
<
Company
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录