Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bc821a56
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,发现更多精彩内容 >>
提交
bc821a56
编写于
10月 14, 2010
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added test_has_many_through_has_many_with_has_many_through_habtm_source_reflection and make it pass
上级
22782e2c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
30 addition
and
4 deletion
+30
-4
activerecord/lib/active_record/associations/through_association_scope.rb
...b/active_record/associations/through_association_scope.rb
+6
-2
activerecord/test/cases/associations/join_model_test.rb
activerecord/test/cases/associations/join_model_test.rb
+1
-1
activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
...associations/nested_has_many_through_associations_test.rb
+16
-1
activerecord/test/fixtures/categorizations.yml
activerecord/test/fixtures/categorizations.yml
+6
-0
activerecord/test/models/author.rb
activerecord/test/models/author.rb
+1
-0
未找到文件。
activerecord/lib/active_record/associations/through_association_scope.rb
浏览文件 @
bc821a56
...
...
@@ -92,7 +92,11 @@ def construct_through_joins
polymorphic_conditions
(
left
,
left
)
)
when
:has_and_belongs_to_many
raise
NotImplementedError
joins
<<
inner_join_sql
(
right_table_and_alias
,
table_aliases
[
left
].
first
,
left
.
primary_key_name
,
table_aliases
[
right
],
right
.
klass
.
primary_key
)
end
else
case
left
.
source_reflection
.
macro
...
...
@@ -106,7 +110,7 @@ def construct_through_joins
when
:has_many
,
:has_one
if
right
.
macro
==
:has_and_belongs_to_many
join_table
,
right_table
=
table_aliases
[
right
]
right_table_and_alias
=
table_name_and_alias
(
right
.
quoted_table_name
,
right_table
)
right_table_and_alias
=
table_name_and_alias
(
right
.
quoted_table_name
,
right_table
)
else
right_table
=
table_aliases
[
right
]
end
...
...
activerecord/test/cases/associations/join_model_test.rb
浏览文件 @
bc821a56
...
...
@@ -304,7 +304,7 @@ def test_has_many_array_methods_called_by_method_missing
end
def
test_has_many_going_through_join_model_with_custom_foreign_key
assert_equal
[],
posts
(
:thinking
).
authors
assert_equal
[
authors
(
:bob
)
],
posts
(
:thinking
).
authors
assert_equal
[
authors
(
:mary
)],
posts
(
:authorless
).
authors
end
...
...
activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
浏览文件 @
bc821a56
...
...
@@ -25,6 +25,7 @@
require
'models/club'
require
'models/organization'
require
'models/category'
require
'models/categorization'
# NOTE: Some of these tests might not really test "nested" HMT associations, as opposed to ones which
# are just one level deep. But it's all the same thing really, as the "nested" code is being
...
...
@@ -34,7 +35,8 @@
class
NestedHasManyThroughAssociationsTest
<
ActiveRecord
::
TestCase
fixtures
:authors
,
:books
,
:posts
,
:subscriptions
,
:subscribers
,
:tags
,
:taggings
,
:people
,
:readers
,
:references
,
:jobs
,
:ratings
,
:comments
,
:members
,
:member_details
,
:member_types
,
:sponsors
,
:clubs
,
:organizations
,
:categories
,
:categories_posts
:member_types
,
:sponsors
,
:clubs
,
:organizations
,
:categories
,
:categories_posts
,
:categorizations
# Through associations can either use the has_many or has_one macros.
#
...
...
@@ -183,6 +185,19 @@ def test_has_many_through_has_and_belongs_to_many_with_has_many_source_reflectio
# assert_equal [comments(:greetings), comments(:more_greetings)], categories[1].post_comments
end
# has_many through
# Source: has_many through a habtm
# Through: has_many through
def
test_has_many_through_has_many_with_has_many_through_habtm_source_reflection
assert_equal
[
comments
(
:greetings
),
comments
(
:more_greetings
)],
authors
(
:bob
).
category_post_comments
authors
=
Author
.
joins
(
:category_post_comments
).
where
(
'comments.id'
=>
comments
(
:does_it_hurt
).
id
)
assert_equal
[
authors
(
:david
),
authors
(
:mary
)],
authors
comments
=
Author
.
joins
(
:category_post_comments
)
assert_equal
[
comments
(
:greetings
),
comments
(
:more_greetings
)],
comments
[
2
].
category_post_comments
end
# TODO: has_many through
# Source: belongs_to
# Through: has_many through
...
...
activerecord/test/fixtures/categorizations.yml
浏览文件 @
bc821a56
...
...
@@ -15,3 +15,9 @@ mary_thinking_general:
author_id
:
2
post_id
:
2
category_id
:
1
bob_misc_by_bob_technology
:
id
:
4
author_id
:
3
post_id
:
8
category_id
:
2
activerecord/test/models/author.rb
浏览文件 @
bc821a56
...
...
@@ -101,6 +101,7 @@ def testing_proxy_target
belongs_to
:author_address_extra
,
:dependent
=>
:delete
,
:class_name
=>
"AuthorAddress"
has_many
:post_categories
,
:through
=>
:posts
,
:source
=>
:categories
has_many
:category_post_comments
,
:through
=>
:categories
,
:source
=>
:post_comments
scope
:relation_include_posts
,
includes
(
:posts
)
scope
:relation_include_tags
,
includes
(
:tags
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录