Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
555d0163
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,发现更多精彩内容 >>
提交
555d0163
编写于
3月 27, 2011
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Quote find_in_batches ORDER BY clause [#6620 state:resolved]
上级
a9dafbb2
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
33 addition
and
3 deletion
+33
-3
activerecord/lib/active_record/attribute_methods/primary_key.rb
...record/lib/active_record/attribute_methods/primary_key.rb
+12
-1
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+1
-1
activerecord/lib/active_record/relation/batches.rb
activerecord/lib/active_record/relation/batches.rb
+1
-1
activerecord/test/cases/batches_test.rb
activerecord/test/cases/batches_test.rb
+10
-0
activerecord/test/cases/primary_keys_test.rb
activerecord/test/cases/primary_keys_test.rb
+9
-0
未找到文件。
activerecord/lib/active_record/attribute_methods/primary_key.rb
浏览文件 @
555d0163
...
...
@@ -17,6 +17,11 @@ def primary_key
@primary_key
||=
reset_primary_key
end
# Returns a quoted version of the primary key name, used to construct SQL statements.
def
quoted_primary_key
@quoted_primary_key
||=
connection
.
quote_column_name
(
primary_key
)
end
def
reset_primary_key
#:nodoc:
key
=
self
==
base_class
?
get_primary_key
(
base_class
.
name
)
:
base_class
.
primary_key
...
...
@@ -43,7 +48,12 @@ def get_primary_key(base_name) #:nodoc:
end
attr_accessor
:original_primary_key
attr_writer
:primary_key
# Attribute writer for the primary key column
def
primary_key
=
(
value
)
@quoted_primary_key
=
nil
@primary_key
=
value
end
# Sets the name of the primary key column to use to the given value,
# or (if the value is nil or false) to the value returned by the given
...
...
@@ -53,6 +63,7 @@ def get_primary_key(base_name) #:nodoc:
# set_primary_key "sysid"
# end
def
set_primary_key
(
value
=
nil
,
&
block
)
@quoted_primary_key
=
nil
@primary_key
||=
''
self
.
original_primary_key
=
@primary_key
value
&&=
value
.
to_s
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
555d0163
...
...
@@ -12,7 +12,7 @@ class Relation
# These are explicitly delegated to improve performance (avoids method_missing)
delegate
:to_xml
,
:to_yaml
,
:length
,
:collect
,
:map
,
:each
,
:all?
,
:include?
,
:to
=>
:to_a
delegate
:table_name
,
:primary_key
,
:to
=>
:klass
delegate
:table_name
,
:
quoted_table_name
,
:primary_key
,
:quoted_
primary_key
,
:to
=>
:klass
attr_reader
:table
,
:klass
,
:loaded
attr_accessor
:extensions
...
...
activerecord/lib/active_record/relation/batches.rb
浏览文件 @
555d0163
...
...
@@ -83,7 +83,7 @@ def find_in_batches(options = {})
private
def
batch_order
"
#{
table_name
}
.
#{
primary_key
}
ASC"
"
#{
quoted_table_name
}
.
#{
quoted_
primary_key
}
ASC"
end
end
end
activerecord/test/cases/batches_test.rb
浏览文件 @
555d0163
...
...
@@ -83,4 +83,14 @@ def test_find_in_batches_shouldnt_excute_query_unless_needed
Post
.
find_in_batches
(
:batch_size
=>
post_count
+
1
)
{
|
batch
|
assert_kind_of
Array
,
batch
}
end
end
def
test_find_in_batches_should_quote_batch_order
c
=
Post
.
connection
assert_sql
(
/ORDER BY
#{
c
.
quote_table_name
(
'posts'
)
}
.
#{
c
.
quote_column_name
(
'id'
)
}
/
)
do
Post
.
find_in_batches
(
:batch_size
=>
1
)
do
|
batch
|
assert_kind_of
Array
,
batch
assert_kind_of
Post
,
batch
.
first
end
end
end
end
activerecord/test/cases/primary_keys_test.rb
浏览文件 @
555d0163
...
...
@@ -136,4 +136,13 @@ def test_primary_key_returns_nil_if_it_does_not_exist
assert_nil
ActiveRecord
::
Base
.
connection
.
primary_key
(
'developers_projects'
)
end
end
def
test_quoted_primary_key_after_set_primary_key
k
=
Class
.
new
(
ActiveRecord
::
Base
)
assert_equal
k
.
connection
.
quote_column_name
(
"id"
),
k
.
quoted_primary_key
k
.
primary_key
=
"foo"
assert_equal
k
.
connection
.
quote_column_name
(
"foo"
),
k
.
quoted_primary_key
k
.
set_primary_key
"bar"
assert_equal
k
.
connection
.
quote_column_name
(
"bar"
),
k
.
quoted_primary_key
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录