Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
915ea5ea
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,发现更多精彩内容 >>
提交
915ea5ea
编写于
10月 19, 2010
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support the :primary_key option on a through reflection in a nested through association
上级
0ceb3429
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
32 addition
and
7 deletion
+32
-7
activerecord/lib/active_record/associations/through_association_scope.rb
...b/active_record/associations/through_association_scope.rb
+2
-5
activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
...associations/nested_has_many_through_associations_test.rb
+16
-1
activerecord/test/fixtures/authors.yml
activerecord/test/fixtures/authors.yml
+2
-0
activerecord/test/models/author.rb
activerecord/test/models/author.rb
+3
-0
activerecord/test/models/organization.rb
activerecord/test/models/organization.rb
+7
-1
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+2
-0
未找到文件。
activerecord/lib/active_record/associations/through_association_scope.rb
浏览文件 @
915ea5ea
...
...
@@ -76,14 +76,11 @@ def construct_through_joins
right_table_and_alias
=
table_name_and_alias
(
right
.
quoted_table_name
,
table_aliases
[
right
])
if
left
.
source_reflection
.
nil?
# TODO: Perhaps need to pay attention to left.options[:primary_key] and
# left.options[:foreign_key] in places here
case
left
.
macro
when
:belongs_to
joins
<<
inner_join_sql
(
right_table_and_alias
,
table_aliases
[
left
],
left
.
klass
.
primary_key
,
table_aliases
[
left
],
left
.
association_
primary_key
,
table_aliases
[
right
],
left
.
primary_key_name
,
reflection_conditions
(
right_index
)
)
...
...
@@ -91,7 +88,7 @@ def construct_through_joins
joins
<<
inner_join_sql
(
right_table_and_alias
,
table_aliases
[
left
],
left
.
primary_key_name
,
table_aliases
[
right
],
right
.
klass
.
primary_key
,
table_aliases
[
right
],
right
.
association_
primary_key
,
polymorphic_conditions
(
left
,
left
),
reflection_conditions
(
right_index
)
)
...
...
activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
浏览文件 @
915ea5ea
...
...
@@ -21,6 +21,7 @@
require
'models/category'
require
'models/categorization'
require
'models/membership'
require
'models/essay'
# 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
...
...
@@ -31,7 +32,7 @@ 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
,
:categorizations
,
:memberships
:categorizations
,
:memberships
,
:essays
# Through associations can either use the has_many or has_one macros.
#
...
...
@@ -440,6 +441,20 @@ def test_nested_has_many_through_with_conditions_on_source_associations
end
end
def
test_nested_has_many_through_with_foreign_key_option_on_the_source_reflection_through_reflection
assert_equal
[
categories
(
:general
)],
organizations
(
:nsa
).
author_essay_categories
organizations
=
Organization
.
joins
(
:author_essay_categories
).
where
(
'categories.id'
=>
categories
(
:general
).
id
)
assert_equal
[
organizations
(
:nsa
)],
organizations
assert_equal
categories
(
:general
),
organizations
(
:nsa
).
author_owned_essay_category
organizations
=
Organization
.
joins
(
:author_owned_essay_category
).
where
(
'categories.id'
=>
categories
(
:general
).
id
)
assert_equal
[
organizations
(
:nsa
)],
organizations
end
private
def
assert_includes_and_joins_equal
(
query
,
expected
,
association
)
...
...
activerecord/test/fixtures/authors.yml
浏览文件 @
915ea5ea
...
...
@@ -3,6 +3,8 @@ david:
name
:
David
author_address_id
:
1
author_address_extra_id
:
2
organization_id
:
No Such Agency
owned_essay_id
:
A Modest Proposal
mary
:
id
:
2
...
...
activerecord/test/models/author.rb
浏览文件 @
915ea5ea
...
...
@@ -110,6 +110,9 @@ def testing_proxy_target
has_many
:essays_2
,
:primary_key
=>
:name
,
:class_name
=>
'Essay'
,
:foreign_key
=>
:author_id
has_many
:essay_categories_2
,
:through
=>
:essays_2
,
:source
=>
:category
belongs_to
:owned_essay
,
:primary_key
=>
:name
,
:class_name
=>
'Essay'
has_one
:owned_essay_category
,
:through
=>
:owned_essay
,
:source
=>
:category
belongs_to
:author_address
,
:dependent
=>
:destroy
belongs_to
:author_address_extra
,
:dependent
=>
:delete
,
:class_name
=>
"AuthorAddress"
...
...
activerecord/test/models/organization.rb
浏览文件 @
915ea5ea
...
...
@@ -2,5 +2,11 @@ class Organization < ActiveRecord::Base
has_many
:member_details
has_many
:members
,
:through
=>
:member_details
has_many
:authors
,
:primary_key
=>
:name
has_many
:author_essay_categories
,
:through
=>
:authors
,
:source
=>
:essay_categories
has_one
:author
,
:primary_key
=>
:name
has_one
:author_owned_essay_category
,
:through
=>
:author
,
:source
=>
:owned_essay_category
scope
:clubs
,
{
:from
=>
'clubs'
}
end
\ No newline at end of file
end
activerecord/test/schema/schema.rb
浏览文件 @
915ea5ea
...
...
@@ -44,6 +44,8 @@ def create_table(*args, &block)
t
.
string
:name
,
:null
=>
false
t
.
integer
:author_address_id
t
.
integer
:author_address_extra_id
t
.
string
:organization_id
t
.
string
:owned_essay_id
end
create_table
:author_addresses
,
:force
=>
true
do
|
t
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录