Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9a958a3d
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,发现更多精彩内容 >>
提交
9a958a3d
编写于
10月 07, 2009
作者:
E
Emilio Tagua
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Relations: Added offset when finding with associations. Delegate array instance
methods to to_a.
上级
aadb09b1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
7 addition
and
10 deletion
+7
-10
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+3
-5
activerecord/test/cases/relations_test.rb
activerecord/test/cases/relations_test.rb
+4
-5
未找到文件。
activerecord/lib/active_record/relation.rb
浏览文件 @
9a958a3d
module
ActiveRecord
class
Relation
delegate
:to_sql
,
:to
=>
:relation
delegate
:length
,
:collect
,
:find
,
:map
,
:each
,
:to
=>
:to_a
attr_reader
:relation
,
:klass
def
initialize
(
klass
,
relation
)
...
...
@@ -34,7 +35,8 @@ def to_a
:group
=>
@relation
.
send
(
:group_clauses
).
join
(
', '
),
:order
=>
@relation
.
send
(
:order_clauses
).
join
(
', '
),
:conditions
=>
@relation
.
send
(
:where_clauses
).
join
(
"
\n\t
AND "
),
:limit
=>
@relation
.
taken
:limit
=>
@relation
.
taken
,
:offset
=>
@relation
.
skipped
},
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
@eager_load_associations
,
nil
))
end
...
...
@@ -49,10 +51,6 @@ def to_a
records
end
def
each
(
&
block
)
to_a
.
each
(
&
block
)
end
def
first
@relation
=
@relation
.
take
(
1
)
to_a
.
first
...
...
activerecord/test/cases/relations_test.rb
浏览文件 @
9a958a3d
...
...
@@ -122,12 +122,12 @@ def test_default_scope_with_conditions_string
end
def
test_default_scope_with_conditions_hash
assert_equal
Developer
.
find_all_by_name
(
'Jamis'
).
map
(
&
:id
).
sort
,
DeveloperCalledJamis
.
all
.
to_a
.
map
(
&
:id
).
sort
assert_equal
Developer
.
find_all_by_name
(
'Jamis'
).
map
(
&
:id
).
sort
,
DeveloperCalledJamis
.
all
.
map
(
&
:id
).
sort
assert_equal
'Jamis'
,
DeveloperCalledJamis
.
create!
.
name
end
def
test_loading_with_one_association
posts
=
Post
.
all
(
:include
=>
:comments
)
.
to_a
posts
=
Post
.
all
(
:include
=>
:comments
)
post
=
posts
.
find
{
|
p
|
p
.
id
==
1
}
assert_equal
2
,
post
.
comments
.
size
assert
post
.
comments
.
include?
(
comments
(
:greetings
))
...
...
@@ -136,16 +136,15 @@ def test_loading_with_one_association
assert_equal
2
,
post
.
comments
.
size
assert
post
.
comments
.
include?
(
comments
(
:greetings
))
posts
=
Post
.
all
(
:include
=>
:last_comment
)
.
to_a
posts
=
Post
.
all
(
:include
=>
:last_comment
)
post
=
posts
.
find
{
|
p
|
p
.
id
==
1
}
assert_equal
Post
.
find
(
1
).
last_comment
,
post
.
last_comment
end
def
test_loading_with_one_association_with_non_preload
posts
=
Post
.
all
(
:include
=>
:last_comment
,
:order
=>
'comments.id DESC'
)
.
to_a
posts
=
Post
.
all
(
:include
=>
:last_comment
,
:order
=>
'comments.id DESC'
)
post
=
posts
.
find
{
|
p
|
p
.
id
==
1
}
assert_equal
Post
.
find
(
1
).
last_comment
,
post
.
last_comment
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录