Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e1175d99
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,发现更多精彩内容 >>
提交
e1175d99
编写于
6月 09, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15596 from eileencodes/add-has_one-method-and-reuse
add has_one? method and reuse instead of checking macro
上级
32b6873d
5a0b184c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
9 addition
and
5 deletion
+9
-5
activerecord/lib/active_record/associations/association.rb
activerecord/lib/active_record/associations/association.rb
+1
-1
activerecord/lib/active_record/associations/belongs_to_association.rb
.../lib/active_record/associations/belongs_to_association.rb
+1
-1
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+1
-1
activerecord/lib/active_record/autosave_association.rb
activerecord/lib/active_record/autosave_association.rb
+1
-1
activerecord/lib/active_record/reflection.rb
activerecord/lib/active_record/reflection.rb
+5
-1
未找到文件。
activerecord/lib/active_record/associations/association.rb
浏览文件 @
e1175d99
...
...
@@ -179,7 +179,7 @@ def find_target?
def
creation_attributes
attributes
=
{}
if
(
reflection
.
macro
==
:has_one
||
reflection
.
macro
==
:has_many
)
&&
!
options
[
:through
]
if
(
reflection
.
has_one?
||
reflection
.
macro
==
:has_many
)
&&
!
options
[
:through
]
attributes
[
reflection
.
foreign_key
]
=
owner
[
reflection
.
active_record_primary_key
]
if
reflection
.
options
[
:as
]
...
...
activerecord/lib/active_record/associations/belongs_to_association.rb
浏览文件 @
e1175d99
...
...
@@ -92,7 +92,7 @@ def foreign_key_present?
# has_one associations.
def
invertible_for?
(
record
)
inverse
=
inverse_reflection_for
(
record
)
inverse
&&
inverse
.
macro
==
:has_one
inverse
&&
inverse
.
has_one?
end
def
target_id
...
...
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
e1175d99
...
...
@@ -107,7 +107,7 @@ def build_record(attributes)
if
inverse
if
inverse
.
macro
==
:has_many
record
.
send
(
inverse
.
name
)
<<
build_through_record
(
record
)
elsif
inverse
.
macro
==
:has_one
elsif
inverse
.
has_one?
record
.
send
(
"
#{
inverse
.
name
}
="
,
build_through_record
(
record
))
end
end
...
...
activerecord/lib/active_record/autosave_association.rb
浏览文件 @
e1175d99
...
...
@@ -187,7 +187,7 @@ def add_autosave_association_callbacks(reflection)
# Doesn't use after_save as that would save associations added in after_create/after_update twice
after_create
save_method
after_update
save_method
elsif
reflection
.
macro
==
:has_one
elsif
reflection
.
has_one?
define_method
(
save_method
)
{
save_has_one_association
(
reflection
)
}
unless
method_defined?
(
save_method
)
# Configures two callbacks instead of a single after_save so that
# the model may rely on their execution order relative to its
...
...
activerecord/lib/active_record/reflection.rb
浏览文件 @
e1175d99
...
...
@@ -400,6 +400,10 @@ def belongs_to?
macro
==
:belongs_to
end
def
has_one?
macro
==
:has_one
end
def
association_class
case
macro
when
:belongs_to
...
...
@@ -746,7 +750,7 @@ def check_validity!
raise
HasManyThroughAssociationPolymorphicSourceError
.
new
(
active_record
.
name
,
self
,
source_reflection
)
end
if
macro
==
:has_one
&&
through_reflection
.
collection?
if
has_one?
&&
through_reflection
.
collection?
raise
HasOneThroughCantAssociateThroughCollection
.
new
(
active_record
.
name
,
self
,
through_reflection
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录