Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
83f24afd
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,发现更多精彩内容 >>
提交
83f24afd
编写于
12月 27, 2009
作者:
P
Pratik Naik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add new finder methods to association collection.
上级
f3741506
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
38 addition
and
13 deletion
+38
-13
activerecord/CHANGELOG
activerecord/CHANGELOG
+10
-0
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+2
-2
activerecord/lib/active_record/associations/association_collection.rb
.../lib/active_record/associations/association_collection.rb
+17
-2
activerecord/lib/active_record/autosave_association.rb
activerecord/lib/active_record/autosave_association.rb
+2
-2
activerecord/test/cases/associations/has_many_through_associations_test.rb
.../cases/associations/has_many_through_associations_test.rb
+4
-4
activerecord/test/cases/batches_test.rb
activerecord/test/cases/batches_test.rb
+1
-1
activerecord/test/cases/named_scope_test.rb
activerecord/test/cases/named_scope_test.rb
+2
-2
未找到文件。
activerecord/CHANGELOG
浏览文件 @
83f24afd
*Edge*
* Add new finder methods to association collection. [Pratik Naik]
class User < ActiveRecord::Base
has_many :items
end
user = User.first
user.items.where(:items => {:colour => 'red'})
user.items.select('items.id')
* Add relation.reload to force reloading the records. [Pratik Naik]
topics = Topic.scoped
...
...
activerecord/lib/active_record/associations.rb
浏览文件 @
83f24afd
...
...
@@ -1382,9 +1382,9 @@ def collection_reader_method(reflection, association_proxy_class)
if
reflection
.
through_reflection
&&
reflection
.
source_reflection
.
belongs_to?
through
=
reflection
.
through_reflection
primary_key
=
reflection
.
source_reflection
.
primary_key_name
send
(
through
.
name
).
all
(
:select
=>
"DISTINCT
#{
through
.
quoted_table_name
}
.
#{
primary_key
}
"
).
map!
(
&
:"
#{
primary_key
}
"
)
send
(
through
.
name
).
select
(
"DISTINCT
#{
through
.
quoted_table_name
}
.
#{
primary_key
}
"
).
map!
(
&
:"
#{
primary_key
}
"
)
else
send
(
reflection
.
name
).
all
(
:select
=>
"
#{
reflection
.
quoted_table_name
}
.
#{
reflection
.
klass
.
primary_key
}
"
).
map!
(
&
:id
)
send
(
reflection
.
name
).
select
(
"
#{
reflection
.
quoted_table_name
}
.
#{
reflection
.
klass
.
primary_key
}
"
).
map!
(
&
:id
)
end
end
end
...
...
activerecord/lib/active_record/associations/association_collection.rb
浏览文件 @
83f24afd
...
...
@@ -21,6 +21,21 @@ def initialize(owner, reflection)
construct_sql
end
delegate
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:to
=>
:scoped
def
select
(
select
=
nil
,
&
block
)
if
block_given?
load_target
@target
.
select
(
&
block
)
else
scoped
.
select
(
select
)
end
end
def
scoped
with_scope
(
construct_scope
)
{
@reflection
.
klass
.
scoped
}
end
def
find
(
*
args
)
options
=
args
.
extract_options!
...
...
activerecord/lib/active_record/autosave_association.rb
浏览文件 @
83f24afd
...
...
@@ -221,9 +221,9 @@ def associated_records_to_validate_or_save(association, new_record, autosave)
if
new_record
association
elsif
association
.
loaded?
autosave
?
association
:
association
.
select
{
|
record
|
record
.
new_record?
}
autosave
?
association
:
association
.
find_all
{
|
record
|
record
.
new_record?
}
else
autosave
?
association
.
target
:
association
.
target
.
select
{
|
record
|
record
.
new_record?
}
autosave
?
association
.
target
:
association
.
target
.
find_all
{
|
record
|
record
.
new_record?
}
end
end
...
...
activerecord/test/cases/associations/has_many_through_associations_test.rb
浏览文件 @
83f24afd
...
...
@@ -140,23 +140,23 @@ def test_replace_association
def
test_replace_order_is_preserved
posts
(
:welcome
).
people
.
clear
posts
(
:welcome
).
people
=
[
people
(
:david
),
people
(
:michael
)]
assert_equal
[
people
(
:david
).
id
,
people
(
:michael
).
id
],
posts
(
:welcome
).
readers
.
all
(
:order
=>
'id'
).
map
(
&
:person_id
)
assert_equal
[
people
(
:david
).
id
,
people
(
:michael
).
id
],
posts
(
:welcome
).
readers
.
order
(
'id'
).
map
(
&
:person_id
)
# Test the inverse order in case the first success was a coincidence
posts
(
:welcome
).
people
.
clear
posts
(
:welcome
).
people
=
[
people
(
:michael
),
people
(
:david
)]
assert_equal
[
people
(
:michael
).
id
,
people
(
:david
).
id
],
posts
(
:welcome
).
readers
.
all
(
:order
=>
'id'
).
map
(
&
:person_id
)
assert_equal
[
people
(
:michael
).
id
,
people
(
:david
).
id
],
posts
(
:welcome
).
readers
.
order
(
'id'
).
map
(
&
:person_id
)
end
def
test_replace_by_id_order_is_preserved
posts
(
:welcome
).
people
.
clear
posts
(
:welcome
).
person_ids
=
[
people
(
:david
).
id
,
people
(
:michael
).
id
]
assert_equal
[
people
(
:david
).
id
,
people
(
:michael
).
id
],
posts
(
:welcome
).
readers
.
all
(
:order
=>
'id'
).
map
(
&
:person_id
)
assert_equal
[
people
(
:david
).
id
,
people
(
:michael
).
id
],
posts
(
:welcome
).
readers
.
order
(
'id'
).
map
(
&
:person_id
)
# Test the inverse order in case the first success was a coincidence
posts
(
:welcome
).
people
.
clear
posts
(
:welcome
).
person_ids
=
[
people
(
:michael
).
id
,
people
(
:david
).
id
]
assert_equal
[
people
(
:michael
).
id
,
people
(
:david
).
id
],
posts
(
:welcome
).
readers
.
all
(
:order
=>
'id'
).
map
(
&
:person_id
)
assert_equal
[
people
(
:michael
).
id
,
people
(
:david
).
id
],
posts
(
:welcome
).
readers
.
order
(
'id'
).
map
(
&
:person_id
)
end
def
test_associate_with_create
...
...
activerecord/test/cases/batches_test.rb
浏览文件 @
83f24afd
...
...
@@ -5,7 +5,7 @@ class EachTest < ActiveRecord::TestCase
fixtures
:posts
def
setup
@posts
=
Post
.
all
(
:order
=>
"id asc"
)
@posts
=
Post
.
order
(
"id asc"
)
@total
=
Post
.
count
end
...
...
activerecord/test/cases/named_scope_test.rb
浏览文件 @
83f24afd
...
...
@@ -345,8 +345,8 @@ def test_chaining_should_use_latest_conditions_when_creating
def
test_chaining_should_use_latest_conditions_when_searching
# Normal hash conditions
assert_equal
Topic
.
all
(
:conditions
=>
{
:approved
=>
true
}
).
to_a
,
Topic
.
rejected
.
approved
.
all
.
to_a
assert_equal
Topic
.
all
(
:conditions
=>
{
:approved
=>
false
}
).
to_a
,
Topic
.
approved
.
rejected
.
all
.
to_a
assert_equal
Topic
.
where
(
:approved
=>
true
).
to_a
,
Topic
.
rejected
.
approved
.
all
.
to_a
assert_equal
Topic
.
where
(
:approved
=>
false
).
to_a
,
Topic
.
approved
.
rejected
.
all
.
to_a
# Nested hash conditions with same keys
assert_equal
[
posts
(
:sti_comments
)],
Post
.
with_special_comments
.
with_very_special_comments
.
all
.
to_a
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录