Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
02207dc0
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,发现更多精彩内容 >>
提交
02207dc0
编写于
12月 28, 2009
作者:
P
Pratik Naik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Model.readonly and association_collection#readonly finder method
上级
5156507e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
25 addition
and
19 deletion
+25
-19
activerecord/CHANGELOG
activerecord/CHANGELOG
+5
-0
activerecord/lib/active_record/associations/association_collection.rb
.../lib/active_record/associations/association_collection.rb
+1
-1
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+1
-1
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+1
-1
activerecord/test/cases/readonly_test.rb
activerecord/test/cases/readonly_test.rb
+17
-16
未找到文件。
activerecord/CHANGELOG
浏览文件 @
02207dc0
*Edge*
* Add Model.readonly and association_collection#readonly finder method. [Pratik Naik]
Post.readonly.to_a # Load all posts in readonly mode
@user.items.readonly(false).to_a # Load all the user items in writable mode
* Add .lock finder method [Pratik Naik]
User.lock.where(:name => 'lifo').to_a
...
...
activerecord/lib/active_record/associations/association_collection.rb
浏览文件 @
02207dc0
...
...
@@ -21,7 +21,7 @@ def initialize(owner, reflection)
construct_sql
end
delegate
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:from
,
:lock
,
:to
=>
:scoped
delegate
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:from
,
:lock
,
:
readonly
,
:
to
=>
:scoped
def
select
(
select
=
nil
,
&
block
)
if
block_given?
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
02207dc0
...
...
@@ -652,7 +652,7 @@ def find(*args)
end
end
delegate
:select
,
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:from
,
:lock
,
:to
=>
:scoped
delegate
:select
,
:group
,
:order
,
:limit
,
:joins
,
:where
,
:preload
,
:eager_load
,
:from
,
:lock
,
:
readonly
,
:
to
=>
:scoped
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
02207dc0
module
ActiveRecord
class
Relation
delegate
:to_sql
,
:to
=>
:relation
delegate
:length
,
:collect
,
:map
,
:each
,
:to
=>
:to_a
delegate
:length
,
:collect
,
:map
,
:each
,
:
all?
,
:
to
=>
:to_a
attr_reader
:relation
,
:klass
,
:associations_to_preload
,
:eager_load_associations
def
initialize
(
klass
,
relation
,
readonly
=
false
,
preload
=
[],
eager_load
=
[])
...
...
activerecord/test/cases/readonly_test.rb
浏览文件 @
02207dc0
...
...
@@ -33,19 +33,20 @@ def test_cant_save_readonly_record
def
test_find_with_readonly_option
Developer
.
find
(
:all
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
find
(
:all
,
:readonly
=>
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
find
(
:all
,
:readonly
=>
true
).
each
{
|
d
|
assert
d
.
readonly?
}
Developer
.
readonly
(
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
readonly
(
true
).
each
{
|
d
|
assert
d
.
readonly?
}
Developer
.
readonly
.
each
{
|
d
|
assert
d
.
readonly?
}
end
def
test_find_with_joins_option_implies_readonly
# Blank joins don't count.
Developer
.
find
(
:all
,
:joins
=>
' '
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
find
(
:all
,
:joins
=>
' '
,
:readonly
=>
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
joins
(
' '
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
joins
(
' '
).
readonly
(
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
# Others do.
Developer
.
find
(
:all
,
:joins
=>
', projects'
).
each
{
|
d
|
assert
d
.
readonly?
}
Developer
.
find
(
:all
,
:joins
=>
', projects'
,
:readonly
=>
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
Developer
.
joins
(
', projects'
).
each
{
|
d
|
assert
d
.
readonly?
}
Developer
.
joins
(
', projects'
).
readonly
(
false
).
each
{
|
d
|
assert
!
d
.
readonly?
}
end
...
...
@@ -54,7 +55,7 @@ def test_habtm_find_readonly
assert
!
dev
.
projects
.
empty?
assert
dev
.
projects
.
all?
(
&
:readonly?
)
assert
dev
.
projects
.
find
(
:all
).
all?
(
&
:readonly?
)
assert
dev
.
projects
.
find
(
:all
,
:readonly
=>
true
).
all?
(
&
:readonly?
)
assert
dev
.
projects
.
readonly
(
true
).
all?
(
&
:readonly?
)
end
def
test_has_many_find_readonly
...
...
@@ -62,7 +63,7 @@ def test_has_many_find_readonly
assert
!
post
.
comments
.
empty?
assert
!
post
.
comments
.
any?
(
&
:readonly?
)
assert
!
post
.
comments
.
find
(
:all
).
any?
(
&
:readonly?
)
assert
post
.
comments
.
find
(
:all
,
:readonly
=>
true
).
all?
(
&
:readonly?
)
assert
post
.
comments
.
readonly
(
true
).
all?
(
&
:readonly?
)
end
def
test_has_many_with_through_is_not_implicitly_marked_readonly
...
...
@@ -73,14 +74,14 @@ def test_has_many_with_through_is_not_implicitly_marked_readonly
def
test_readonly_scoping
Post
.
with_scope
(
:find
=>
{
:conditions
=>
'1=1'
})
do
assert
!
Post
.
find
(
1
).
readonly?
assert
Post
.
find
(
1
,
:readonly
=>
true
).
readonly?
assert
!
Post
.
find
(
1
,
:readonly
=>
false
).
readonly?
assert
Post
.
readonly
(
true
).
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
Post
.
with_scope
(
:find
=>
{
:joins
=>
' '
})
do
assert
!
Post
.
find
(
1
).
readonly?
assert
Post
.
find
(
1
,
:readonly
=>
true
).
readonly?
assert
!
Post
.
find
(
1
,
:readonly
=>
false
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
# Oracle barfs on this because the join includes unqualified and
...
...
@@ -88,15 +89,15 @@ def test_readonly_scoping
unless
current_adapter?
(
:OracleAdapter
)
Post
.
with_scope
(
:find
=>
{
:joins
=>
', developers'
})
do
assert
Post
.
find
(
1
).
readonly?
assert
Post
.
find
(
1
,
:readonly
=>
true
).
readonly?
assert
!
Post
.
find
(
1
,
:readonly
=>
false
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
end
Post
.
with_scope
(
:find
=>
{
:readonly
=>
true
})
do
assert
Post
.
find
(
1
).
readonly?
assert
Post
.
find
(
1
,
:readonly
=>
true
).
readonly?
assert
!
Post
.
find
(
1
,
:readonly
=>
false
).
readonly?
assert
Post
.
readonly
.
find
(
1
).
readonly?
assert
!
Post
.
readonly
(
false
).
find
(
1
).
readonly?
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录