Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
049caa9e
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 搜索 >>
提交
049caa9e
编写于
11月 09, 2014
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17217 from codeodor/fix-17119
Ensure HABTM relationships produce valid class names (Fixes #17119)
上级
47704af5
f43f56e1
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
25 addition
and
3 deletion
+25
-3
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+1
-1
activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
...ve_record/associations/builder/has_and_belongs_to_many.rb
+1
-1
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
...associations/has_and_belongs_to_many_associations_test.rb
+10
-1
activerecord/test/fixtures/computers.yml
activerecord/test/fixtures/computers.yml
+5
-0
activerecord/test/fixtures/developers.yml
activerecord/test/fixtures/developers.yml
+1
-0
activerecord/test/models/developer.rb
activerecord/test/models/developer.rb
+2
-0
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+5
-0
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
049caa9e
...
...
@@ -1700,7 +1700,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
,
:autosave
,
:validate
,
:join_table
].
each
do
|
k
|
[
:before_add
,
:after_add
,
:before_remove
,
:after_remove
,
:autosave
,
:validate
,
:join_table
,
:class_name
].
each
do
|
k
|
hm_options
[
k
]
=
options
[
k
]
if
options
.
key?
k
end
...
...
activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
浏览文件 @
049caa9e
...
...
@@ -98,7 +98,7 @@ def middle_reflection(join_model)
def
middle_options
(
join_model
)
middle_options
=
{}
middle_options
[
:class
]
=
join_model
middle_options
[
:class
_name
]
=
"
#{
lhs_model
.
name
}
::
#{
join_model
.
name
}
"
middle_options
[
:source
]
=
join_model
.
left_reflection
.
name
if
options
.
key?
:foreign_key
middle_options
[
:foreign_key
]
=
options
[
:foreign_key
]
...
...
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
浏览文件 @
049caa9e
require
"cases/helper"
require
'models/developer'
require
'models/computer'
require
'models/project'
require
'models/company'
require
'models/customer'
...
...
@@ -80,7 +81,7 @@ class SubDeveloper < Developer
class
HasAndBelongsToManyAssociationsTest
<
ActiveRecord
::
TestCase
fixtures
:accounts
,
:companies
,
:categories
,
:posts
,
:categories_posts
,
:developers
,
:projects
,
:developers_projects
,
:parrots
,
:pirates
,
:parrots_pirates
,
:treasures
,
:price_estimates
,
:tags
,
:taggings
:parrots
,
:pirates
,
:parrots_pirates
,
:treasures
,
:price_estimates
,
:tags
,
:taggings
,
:computers
def
setup_data_for_habtm_case
ActiveRecord
::
Base
.
connection
.
execute
(
'delete from countries_treaties'
)
...
...
@@ -883,4 +884,12 @@ def test_redefine_habtm
child
.
special_projects
<<
SpecialProject
.
new
(
"name"
=>
"Special Project"
)
assert
child
.
save
,
'child object should be saved'
end
def
test_habtm_with_reflection_using_class_name_and_fixtures
assert_not_nil
Developer
.
_reflections
[
'shared_computers'
]
# Checking the fixture for named association is important here, because it's the only way
# we've been able to reproduce this bug
assert_not_nil
File
.
read
(
File
.
expand_path
(
"../../../fixtures/developers.yml"
,
__FILE__
)).
index
(
"shared_computers"
)
assert_equal
developers
(
:david
).
shared_computers
.
first
,
computers
(
:laptop
)
end
end
activerecord/test/fixtures/computers.yml
浏览文件 @
049caa9e
...
...
@@ -3,3 +3,8 @@ workstation:
system
:
'
Linux'
developer
:
1
extendedWarranty
:
1
laptop
:
system
:
'
MacOS
1'
developer
:
1
extendedWarranty
:
1
activerecord/test/fixtures/developers.yml
浏览文件 @
049caa9e
...
...
@@ -2,6 +2,7 @@ david:
id
:
1
name
:
David
salary
:
80000
shared_computers
:
laptop
jamis
:
id
:
2
...
...
activerecord/test/models/developer.rb
浏览文件 @
049caa9e
...
...
@@ -15,6 +15,8 @@ def find_most_recent
accepts_nested_attributes_for
:projects
has_and_belongs_to_many
:shared_computers
,
class_name:
"Computer"
has_and_belongs_to_many
:projects_extended_by_name
,
->
{
extending
(
DeveloperProjectsAssociationExtension
)
},
:class_name
=>
"Project"
,
...
...
activerecord/test/schema/schema.rb
浏览文件 @
049caa9e
...
...
@@ -228,6 +228,11 @@ def except(adapter_names_to_exclude)
t
.
integer
:extendedWarranty
,
null:
false
end
create_table
:computers_developers
,
id:
false
,
force:
true
do
|
t
|
t
.
references
:computer
t
.
references
:developer
end
create_table
:contracts
,
force:
true
do
|
t
|
t
.
integer
:developer_id
t
.
integer
:company_id
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录