Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0fd3e4cd
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,发现更多精彩内容 >>
提交
0fd3e4cd
编写于
6月 21, 2008
作者:
M
Mark Catley
提交者:
Jeremy Kemper
6月 22, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix column collision with named_scope and :joins. [#46 state:resolved]
上级
bb6e8eea
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
39 addition
and
3 deletion
+39
-3
activerecord/CHANGELOG
activerecord/CHANGELOG
+2
-0
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+1
-1
activerecord/test/cases/method_scoping_test.rb
activerecord/test/cases/method_scoping_test.rb
+10
-0
activerecord/test/cases/named_scope_test.rb
activerecord/test/cases/named_scope_test.rb
+20
-1
activerecord/test/models/post.rb
activerecord/test/models/post.rb
+6
-1
未找到文件。
activerecord/CHANGELOG
浏览文件 @
0fd3e4cd
*Edge*
* Fix column collision with named_scope and :joins. #46 [Duncan Beevers, Mark Catley]
* db:migrate:down and :up update schema_migrations. #369 [Michael Raidel, RaceCondition]
* PostgreSQL: support :conditions => [':foo::integer', { :foo => 1 }] without treating the ::integer typecast as a bind variable. [Tarmo Tänav]
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
0fd3e4cd
...
...
@@ -1479,7 +1479,7 @@ def type_name_with_module(type_name)
def
construct_finder_sql
(
options
)
scope
=
scope
(
:find
)
sql
=
"SELECT
#{
options
[
:select
]
||
(
scope
&&
scope
[
:select
])
||
(
options
[
:joins
]
&&
quoted_table_name
+
'.*'
)
||
'*'
}
"
sql
=
"SELECT
#{
options
[
:select
]
||
(
scope
&&
scope
[
:select
])
||
(
(
options
[
:joins
]
||
(
scope
&&
scope
[
:joins
]))
&&
quoted_table_name
+
'.*'
)
||
'*'
}
"
sql
<<
"FROM
#{
(
scope
&&
scope
[
:from
])
||
options
[
:from
]
||
quoted_table_name
}
"
add_joins!
(
sql
,
options
,
scope
)
...
...
activerecord/test/cases/method_scoping_test.rb
浏览文件 @
0fd3e4cd
...
...
@@ -87,6 +87,16 @@ def test_scoped_find_include
assert_equal
1
,
scoped_developers
.
size
end
def
test_scoped_find_joins
scoped_developers
=
Developer
.
with_scope
(
:find
=>
{
:joins
=>
'JOIN developers_projects ON id = developer_id'
}
)
do
Developer
.
find
(
:all
,
:conditions
=>
'developers_projects.project_id = 2'
)
end
assert
scoped_developers
.
include?
(
developers
(
:david
))
assert
!
scoped_developers
.
include?
(
developers
(
:jamis
))
assert_equal
1
,
scoped_developers
.
size
assert_equal
developers
(
:david
).
attributes
,
scoped_developers
.
first
.
attributes
end
def
test_scoped_count_include
# with the include, will retrieve only developers for the given project
Developer
.
with_scope
(
:find
=>
{
:include
=>
:projects
})
do
...
...
activerecord/test/cases/named_scope_test.rb
浏览文件 @
0fd3e4cd
...
...
@@ -6,7 +6,7 @@
require
'models/author'
class
NamedScopeTest
<
ActiveRecord
::
TestCase
fixtures
:posts
,
:authors
,
:topics
,
:comments
fixtures
:posts
,
:authors
,
:topics
,
:comments
,
:author_addresses
def
test_implements_enumerable
assert
!
Topic
.
find
(
:all
).
empty?
...
...
@@ -83,6 +83,25 @@ def test_procedural_scopes
assert_equal
topics_written_before_the_second
,
Topic
.
written_before
(
topics
(
:second
).
written_on
)
end
def
test_scopes_with_joins
address
=
author_addresses
(
:david_address
)
posts_with_authors_at_address
=
Post
.
find
(
:all
,
:joins
=>
'JOIN authors ON authors.id = posts.author_id'
,
:conditions
=>
[
'authors.author_address_id = ?'
,
address
.
id
]
)
assert_equal
posts_with_authors_at_address
,
Post
.
with_authors_at_address
(
address
)
end
def
test_scopes_with_joins_respects_custom_select
address
=
author_addresses
(
:david_address
)
posts_with_authors_at_address_titles
=
Post
.
find
(
:all
,
:select
=>
'title'
,
:joins
=>
'JOIN authors ON authors.id = posts.author_id'
,
:conditions
=>
[
'authors.author_address_id = ?'
,
address
.
id
]
)
assert_equal
posts_with_authors_at_address_titles
,
Post
.
with_authors_at_address
(
address
).
find
(
:all
,
:select
=>
'title'
)
end
def
test_extensions
assert_equal
1
,
Topic
.
anonymous_extension
.
one
assert_equal
2
,
Topic
.
named_extension
.
two
...
...
activerecord/test/models/post.rb
浏览文件 @
0fd3e4cd
class
Post
<
ActiveRecord
::
Base
named_scope
:containing_the_letter_a
,
:conditions
=>
"body LIKE '%a%'"
named_scope
:with_authors_at_address
,
lambda
{
|
address
|
{
:conditions
=>
[
'authors.author_address_id = ?'
,
address
.
id
],
:joins
=>
'JOIN authors ON authors.id = posts.author_id'
}
}
belongs_to
:author
do
def
greeting
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录