Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d1e36842
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,发现更多精彩内容 >>
提交
d1e36842
编写于
9月 25, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12359 from arthurnn/inverse_on_callbacks
Make sure inverse_of is visible on the has_many callbacks
上级
e2fd64fe
25ada9b5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
2 deletion
+18
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-1
activerecord/lib/active_record/associations/has_many_association.rb
...rd/lib/active_record/associations/has_many_association.rb
+1
-0
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+7
-0
activerecord/test/models/company.rb
activerecord/test/models/company.rb
+5
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
d1e36842
*
Callbacks on has_many should access the in memory parent if a inverse_of is set.
*arthurnn*
*
`ActiveRecord::ConnectionAdapters.string_to_time`
respects
string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
Fixes: #12278
*kennyj*
...
...
activerecord/lib/active_record/associations/has_many_association.rb
浏览文件 @
d1e36842
...
...
@@ -32,6 +32,7 @@ def handle_dependency
def
insert_record
(
record
,
validate
=
true
,
raise
=
false
)
set_owner_attributes
(
record
)
set_inverse_instance
(
record
)
if
raise
record
.
save!
(
:validate
=>
validate
)
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
d1e36842
...
...
@@ -518,6 +518,13 @@ def test_transactions_when_adding_to_new_record
end
end
def
test_inverse_on_before_validate
firm
=
companies
(
:first_firm
)
assert_queries
(
1
)
do
firm
.
clients_of_firm
<<
Client
.
new
(
"name"
=>
"Natural Company"
)
end
end
def
test_new_aliased_to_build
company
=
companies
(
:first_firm
)
new_client
=
assert_no_queries
{
company
.
clients_of_firm
.
new
(
"name"
=>
"Another Client"
)
}
...
...
activerecord/test/models/company.rb
浏览文件 @
d1e36842
...
...
@@ -39,7 +39,7 @@ class Firm < Company
has_many
:unsorted_clients
,
:class_name
=>
"Client"
has_many
:unsorted_clients_with_symbol
,
:class_name
=>
:Client
has_many
:clients_sorted_desc
,
->
{
order
"id DESC"
},
:class_name
=>
"Client"
has_many
:clients_of_firm
,
->
{
order
"id"
},
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
has_many
:clients_of_firm
,
->
{
order
"id"
},
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:inverse_of
=>
:firm
has_many
:clients_ordered_by_name
,
->
{
order
"name"
},
:class_name
=>
"Client"
has_many
:unvalidated_clients_of_firm
,
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:validate
=>
false
has_many
:dependent_clients_of_firm
,
->
{
order
"id"
},
:foreign_key
=>
"client_of"
,
:class_name
=>
"Client"
,
:dependent
=>
:destroy
...
...
@@ -117,6 +117,10 @@ class Client < Company
has_many
:accounts
,
:through
=>
:firm
,
:source
=>
:accounts
belongs_to
:account
validate
do
firm
end
class
RaisedOnSave
<
RuntimeError
;
end
attr_accessor
:raise_on_save
before_save
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录