Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5da90b34
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,发现更多精彩内容 >>
提交
5da90b34
编写于
12月 08, 2011
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #3890. (Calling proxy_association in scope chain.)
上级
ebd71fd0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
3 deletion
+19
-3
activerecord/lib/active_record/associations/collection_proxy.rb
...record/lib/active_record/associations/collection_proxy.rb
+8
-2
activerecord/test/cases/associations/extension_test.rb
activerecord/test/cases/associations/extension_test.rb
+6
-0
activerecord/test/models/post.rb
activerecord/test/models/post.rb
+5
-1
未找到文件。
activerecord/lib/active_record/associations/collection_proxy.rb
浏览文件 @
5da90b34
...
...
@@ -41,8 +41,7 @@ class CollectionProxy # :nodoc:
delegate
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:includes
,
:from
,
:lock
,
:readonly
,
:having
,
:pluck
,
:to
=>
:scoped
delegate
:target
,
:load_target
,
:loaded?
,
:scoped
,
:to
=>
:@association
delegate
:target
,
:load_target
,
:loaded?
,
:to
=>
:@association
delegate
:select
,
:find
,
:first
,
:last
,
:build
,
:create
,
:create!
,
...
...
@@ -62,6 +61,13 @@ def proxy_association
@association
end
def
scoped
association
=
@association
association
.
scoped
.
extending
do
define_method
(
:proxy_association
)
{
association
}
end
end
def
respond_to?
(
name
,
include_private
=
false
)
super
||
(
load_target
&&
target
.
respond_to?
(
name
,
include_private
))
||
...
...
activerecord/test/cases/associations/extension_test.rb
浏览文件 @
5da90b34
...
...
@@ -71,6 +71,12 @@ def test_extension_name
assert_equal
'MyApplication::Business::DeveloperAssociationNameAssociationExtension'
,
extension_name
(
MyApplication
::
Business
::
Developer
)
end
def
test_proxy_association_after_scoped
post
=
posts
(
:welcome
)
assert_equal
post
.
association
(
:comments
),
post
.
comments
.
the_association
assert_equal
post
.
association
(
:comments
),
post
.
comments
.
scoped
.
the_association
end
private
def
extension_name
(
model
)
...
...
activerecord/test/models/post.rb
浏览文件 @
5da90b34
...
...
@@ -44,6 +44,10 @@ def find_most_recent
def
newest
created
.
last
end
def
the_association
proxy_association
end
end
has_many
:author_favorites
,
:through
=>
:author
...
...
@@ -185,4 +189,4 @@ class PostWithDefaultScope < ActiveRecord::Base
class
SpecialPostWithDefaultScope
<
ActiveRecord
::
Base
self
.
table_name
=
'posts'
default_scope
where
(
:id
=>
[
1
,
5
,
6
])
end
\ No newline at end of file
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录