Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c9c7ee77
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 搜索 >>
提交
c9c7ee77
编写于
3月 05, 2012
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Not need to pass join attributes to association build
上级
e9bf0e31
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
21 addition
and
16 deletion
+21
-16
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+3
-1
activerecord/lib/active_record/associations/through_association.rb
...ord/lib/active_record/associations/through_association.rb
+7
-3
activerecord/test/cases/associations/has_many_through_associations_test.rb
.../cases/associations/has_many_through_associations_test.rb
+2
-3
activerecord/test/models/reader.rb
activerecord/test/models/reader.rb
+9
-0
activerecord/test/models/secure_reader.rb
activerecord/test/models/secure_reader.rb
+0
-9
未找到文件。
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
c9c7ee77
...
...
@@ -73,7 +73,9 @@ def through_association
# association
def
build_through_record
(
record
)
@through_records
[
record
.
object_id
]
||=
begin
through_record
=
through_association
.
build
(
construct_join_attributes
(
record
))
ensure_mutable
through_record
=
through_association
.
build
through_record
.
send
(
"
#{
source_reflection
.
name
}
="
,
record
)
through_record
end
...
...
activerecord/lib/active_record/associations/through_association.rb
浏览文件 @
c9c7ee77
...
...
@@ -37,9 +37,7 @@ def target_scope
# situation it is more natural for the user to just create or modify their join records
# directly as required.
def
construct_join_attributes
(
*
records
)
if
source_reflection
.
macro
!=
:belongs_to
raise
HasManyThroughCantAssociateThroughHasOneOrManyReflection
.
new
(
owner
,
reflection
)
end
ensure_mutable
join_attributes
=
{
source_reflection
.
foreign_key
=>
...
...
@@ -73,6 +71,12 @@ def foreign_key_present?
!
owner
[
through_reflection
.
foreign_key
].
nil?
end
def
ensure_mutable
if
source_reflection
.
macro
!=
:belongs_to
raise
HasManyThroughCantAssociateThroughHasOneOrManyReflection
.
new
(
owner
,
reflection
)
end
end
def
ensure_not_nested
if
reflection
.
nested?
raise
HasManyThroughNestedAssociationsAreReadonly
.
new
(
owner
,
reflection
)
...
...
activerecord/test/cases/associations/has_many_through_associations_test.rb
浏览文件 @
c9c7ee77
...
...
@@ -4,7 +4,6 @@
require
'models/reference'
require
'models/job'
require
'models/reader'
require
'models/secure_reader'
require
'models/comment'
require
'models/tag'
require
'models/tagging'
...
...
@@ -60,7 +59,7 @@ def test_associate_existing
end
def
test_associate_existing_with_strict_mass_assignment_sanitizer
ActiveRecord
::
Base
.
mass_assignment_sanitizer
=
:strict
SecureReader
.
mass_assignment_sanitizer
=
:strict
SecureReader
.
new
...
...
@@ -71,7 +70,7 @@ def test_associate_existing_with_strict_mass_assignment_sanitizer
post
.
secure_people
<<
person
end
ensure
ActiveRecord
::
Base
.
mass_assignment_sanitizer
=
:logger
SecureReader
.
mass_assignment_sanitizer
=
:logger
end
def
test_associate_existing_record_twice_should_add_to_target_twice
...
...
activerecord/test/models/reader.rb
浏览文件 @
c9c7ee77
...
...
@@ -3,3 +3,12 @@ class Reader < ActiveRecord::Base
belongs_to
:person
,
:inverse_of
=>
:readers
belongs_to
:single_person
,
:class_name
=>
'Person'
,
:foreign_key
=>
:person_id
,
:inverse_of
=>
:reader
end
class
SecureReader
<
ActiveRecord
::
Base
self
.
table_name
=
"readers"
belongs_to
:secure_post
,
:class_name
=>
"Post"
,
:foreign_key
=>
"post_id"
belongs_to
:secure_person
,
:inverse_of
=>
:secure_readers
,
:class_name
=>
"Person"
,
:foreign_key
=>
"person_id"
attr_accessible
nil
end
activerecord/test/models/secure_reader.rb
已删除
100644 → 0
浏览文件 @
e9bf0e31
class
SecureReader
<
ActiveRecord
::
Base
self
.
table_name
=
"readers"
belongs_to
:secure_post
,
:class_name
=>
"Post"
,
:foreign_key
=>
"post_id"
belongs_to
:secure_person
,
:inverse_of
=>
:secure_readers
,
:class_name
=>
"Person"
,
:foreign_key
=>
"person_id"
attr_accessible
nil
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录