Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9a1abedc
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,发现更多精彩内容 >>
提交
9a1abedc
编写于
5月 20, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14544 from jefflai2/named_scope_sti
Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
上级
c72d6c91
9c3afdc3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
42 addition
and
5 deletion
+42
-5
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+11
-0
activerecord/lib/active_record/scoping.rb
activerecord/lib/active_record/scoping.rb
+2
-2
activerecord/lib/active_record/scoping/named.rb
activerecord/lib/active_record/scoping/named.rb
+6
-2
activerecord/test/cases/scoping/named_scoping_test.rb
activerecord/test/cases/scoping/named_scoping_test.rb
+6
-1
activerecord/test/fixtures/ratings.yml
activerecord/test/fixtures/ratings.yml
+10
-0
activerecord/test/models/comment.rb
activerecord/test/models/comment.rb
+1
-0
activerecord/test/models/rating.rb
activerecord/test/models/rating.rb
+4
-0
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+2
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
9a1abedc
*
Changed scoped blocks to be executed with
`instance_eval`
Named scopes (i.e. using STI) were previously cached according to
base class so scoped queries made by classes with a common ancestor would
leak. Changed the way scope blocks were called so inheritance rules are
followed during the call and scopes are cached correctly.
Fixes #13466.
*Jefferson Lai*
*
Change belongs_to touch to be consistent with timestamp updates
If a model is set up with a belongs_to: touch relatinoship the parent
...
...
activerecord/lib/active_record/scoping.rb
浏览文件 @
9a1abedc
...
...
@@ -11,11 +11,11 @@ module Scoping
module
ClassMethods
def
current_scope
#:nodoc:
ScopeRegistry
.
value_for
(
:current_scope
,
base_class
.
to_s
)
ScopeRegistry
.
value_for
(
:current_scope
,
self
.
to_s
)
end
def
current_scope
=
(
scope
)
#:nodoc:
ScopeRegistry
.
set_value_for
(
:current_scope
,
base_class
.
to_s
,
scope
)
ScopeRegistry
.
set_value_for
(
:current_scope
,
self
.
to_s
,
scope
)
end
end
...
...
activerecord/lib/active_record/scoping/named.rb
浏览文件 @
9a1abedc
...
...
@@ -148,9 +148,13 @@ def scope(name, body, &block)
extension
=
Module
.
new
(
&
block
)
if
block
singleton_class
.
send
(
:define_method
,
name
)
do
|*
args
|
scope
=
all
.
scoping
{
body
.
call
(
*
args
)
}
if
body
.
respond_to?
(
:to_proc
)
scope
=
all
.
scoping
{
instance_exec
(
*
args
,
&
body
)
}
else
# Body is given as an object instead of a block, so invoke call()
scope
=
all
.
scoping
{
body
.
call
(
*
args
)
}
end
scope
=
scope
.
extending
(
extension
)
if
extension
scope
||
all
end
end
...
...
activerecord/test/cases/scoping/named_scoping_test.rb
浏览文件 @
9a1abedc
...
...
@@ -2,12 +2,13 @@
require
'models/post'
require
'models/topic'
require
'models/comment'
require
'models/rating'
require
'models/reply'
require
'models/author'
require
'models/developer'
class
NamedScopingTest
<
ActiveRecord
::
TestCase
fixtures
:posts
,
:authors
,
:topics
,
:comments
,
:author_addresses
fixtures
:posts
,
:authors
,
:topics
,
:comments
,
:author_addresses
,
:ratings
def
test_implements_enumerable
assert
!
Topic
.
all
.
empty?
...
...
@@ -115,6 +116,10 @@ def test_scope_with_STI
assert_equal
1
,
SpecialPost
.
containing_the_letter_a
.
count
end
def
test_scope_subquery_with_STI
assert_nothing_raised
{
VerySpecialComment
.
special_parent
(
SpecialRating
.
first
).
count
}
end
def
test_has_many_through_associations_have_access_to_scopes
assert_not_equal
Comment
.
containing_the_letter_e
,
authors
(
:david
).
comments
assert
!
Comment
.
containing_the_letter_e
.
empty?
...
...
activerecord/test/fixtures/ratings.yml
浏览文件 @
9a1abedc
...
...
@@ -2,13 +2,23 @@ normal_comment_rating:
id
:
1
comment_id
:
8
value
:
1
type
:
Rating
special_comment_rating
:
id
:
2
comment_id
:
6
value
:
1
type
:
Rating
sub_special_comment_rating
:
id
:
3
comment_id
:
12
value
:
1
type
:
Rating
special_rating
:
id
:
4
comment_id
:
10
value
:
1
type
:
SpecialRating
special_comment_id
:
3
activerecord/test/models/comment.rb
浏览文件 @
9a1abedc
...
...
@@ -39,6 +39,7 @@ class SubSpecialComment < SpecialComment
end
class
VerySpecialComment
<
Comment
scope
:special_parent
,
->
(
special_rating
)
{
where
parent_id:
special_rating
.
special_comment
.
id
}
end
class
CommentThatAutomaticallyAltersPostBody
<
Comment
...
...
activerecord/test/models/rating.rb
浏览文件 @
9a1abedc
...
...
@@ -2,3 +2,7 @@ class Rating < ActiveRecord::Base
belongs_to
:comment
has_many
:taggings
,
:as
=>
:taggable
end
class
SpecialRating
<
Rating
belongs_to
:special_comment
end
activerecord/test/schema/schema.rb
浏览文件 @
9a1abedc
...
...
@@ -595,7 +595,9 @@ def except(adapter_names_to_exclude)
create_table
:ratings
,
force:
true
do
|
t
|
t
.
integer
:comment_id
t
.
integer
:special_comment_id
t
.
integer
:value
t
.
string
:type
end
create_table
:readers
,
force:
true
do
|
t
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录