Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
584a4647
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 搜索 >>
提交
584a4647
编写于
2月 03, 2014
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pass `habtm :autosave` to underlying `hm:t` association. Closes #13923.
上级
b7c7cb1a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
8 deletion
+35
-8
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+7
-0
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+1
-1
activerecord/test/cases/autosave_association_test.rb
activerecord/test/cases/autosave_association_test.rb
+26
-7
activerecord/test/models/pirate.rb
activerecord/test/models/pirate.rb
+1
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
584a4647
*
Pass
`has_and_belongs_to_many`
`:autosave`
option to
the underlying
`has_many :through`
association.
Fixes #13923.
*Yves Senn*
*
PostgreSQL implementation of SchemaStatements#index_name_exists?
The database agnostic implementation does not detect with indexes that are
...
...
activerecord/lib/active_record/associations.rb
浏览文件 @
584a4647
...
...
@@ -1585,7 +1585,7 @@ def destroy_associations
hm_options
[
:through
]
=
middle_reflection
.
name
hm_options
[
:source
]
=
join_model
.
right_reflection
.
name
[
:before_add
,
:after_add
,
:before_remove
,
:after_remove
].
each
do
|
k
|
[
:before_add
,
:after_add
,
:before_remove
,
:after_remove
,
:autosave
].
each
do
|
k
|
hm_options
[
k
]
=
options
[
k
]
if
options
.
key?
k
end
...
...
activerecord/test/cases/autosave_association_test.rb
浏览文件 @
584a4647
...
...
@@ -1183,15 +1183,15 @@ def test_should_not_use_default_invalid_error_on_associated_models
end
def
test_should_default_invalid_error_from_i18n
I18n
.
backend
.
store_translations
(
:en
,
:activerecord
=>
{
:errors
=>
{
:models
=>
{
@associat
ion_name
.
to_s
.
singularize
.
to_sym
=>
{
:blank
=>
"cannot be blank"
}
}
I18n
.
backend
.
store_translations
(
:en
,
activerecord:
{
errors:
{
models:
{
@associat
ed_model_name
.
to_s
.
to_sym
=>
{
blank:
"cannot be blank"
}
}
}})
@pirate
.
send
(
@association_name
).
build
(
:name
=>
''
)
@pirate
.
send
(
@association_name
).
build
(
name:
''
)
assert
!
@pirate
.
valid?
assert_equal
[
"cannot be blank"
],
@pirate
.
errors
[
"
#{
@association_name
}
.name"
]
assert_equal
[
"
#{
@association_name
.
to_s
.
title
ize
}
name cannot be blank"
],
@pirate
.
errors
.
full_messages
assert_equal
[
"
#{
@association_name
.
to_s
.
human
ize
}
name cannot be blank"
],
@pirate
.
errors
.
full_messages
assert
@pirate
.
errors
[
@association_name
].
empty?
ensure
I18n
.
backend
=
I18n
::
Backend
::
Simple
.
new
...
...
@@ -1307,6 +1307,7 @@ class TestAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase
def
setup
super
@association_name
=
:birds
@associated_model_name
=
:bird
@pirate
=
Pirate
.
create
(
:catchphrase
=>
"Don' botharrr talkin' like one, savvy?"
)
@child_1
=
@pirate
.
birds
.
create
(
:name
=>
'Posideons Killer'
)
...
...
@@ -1319,14 +1320,32 @@ def setup
class
TestAutosaveAssociationOnAHasAndBelongsToManyAssociation
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
unless
supports_savepoints?
def
setup
super
@association_name
=
:autosaved_parrots
@associated_model_name
=
:parrot
@habtm
=
true
@pirate
=
Pirate
.
create
(
catchphrase:
"Don' botharrr talkin' like one, savvy?"
)
@child_1
=
@pirate
.
parrots
.
create
(
name:
'Posideons Killer'
)
@child_2
=
@pirate
.
parrots
.
create
(
name:
'Killer bandita Dionne'
)
end
include
AutosaveAssociationOnACollectionAssociationTests
end
class
TestAutosaveAssociationOnAHasAndBelongsToManyAssociationWithAcceptsNestedAttributes
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
unless
supports_savepoints?
def
setup
super
@association_name
=
:parrots
@associated_model_name
=
:parrot
@habtm
=
true
@pirate
=
Pirate
.
create
(
:catchphrase
=>
"Don' botharrr talkin' like one, savvy?"
)
@child_1
=
@pirate
.
parrots
.
create
(
:name
=>
'Posideons Killer'
)
@child_2
=
@pirate
.
parrots
.
create
(
:name
=>
'Killer bandita Dionne'
)
@pirate
=
Pirate
.
create
(
catchphrase:
"Don' botharrr talkin' like one, savvy?"
)
@child_1
=
@pirate
.
parrots
.
create
(
name:
'Posideons Killer'
)
@child_2
=
@pirate
.
parrots
.
create
(
name:
'Killer bandita Dionne'
)
end
include
AutosaveAssociationOnACollectionAssociationTests
...
...
activerecord/test/models/pirate.rb
浏览文件 @
584a4647
...
...
@@ -13,6 +13,7 @@ class Pirate < ActiveRecord::Base
:after_add
=>
proc
{
|
p
,
pa
|
p
.
ship_log
<<
"after_adding_proc_parrot_
#{
pa
.
id
||
'<new>'
}
"
},
:before_remove
=>
proc
{
|
p
,
pa
|
p
.
ship_log
<<
"before_removing_proc_parrot_
#{
pa
.
id
}
"
},
:after_remove
=>
proc
{
|
p
,
pa
|
p
.
ship_log
<<
"after_removing_proc_parrot_
#{
pa
.
id
}
"
}
has_and_belongs_to_many
:autosaved_parrots
,
class_name:
"Parrot"
,
autosave:
true
has_many
:treasures
,
:as
=>
:looter
has_many
:treasure_estimates
,
:through
=>
:treasures
,
:source
=>
:price_estimates
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录