Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6d40d2d3
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,体验更适合开发者的 AI 搜索 >>
提交
6d40d2d3
编写于
9月 30, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle UPDATE/DELETE with OFFSET in Arel
上级
322c5704
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
19 deletion
+35
-19
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+4
-2
activerecord/lib/arel/nodes/delete_statement.rb
activerecord/lib/arel/nodes/delete_statement.rb
+4
-2
activerecord/lib/arel/nodes/update_statement.rb
activerecord/lib/arel/nodes/update_statement.rb
+4
-2
activerecord/lib/arel/tree_manager.rb
activerecord/lib/arel/tree_manager.rb
+5
-0
activerecord/lib/arel/visitors/mysql.rb
activerecord/lib/arel/visitors/mysql.rb
+16
-12
activerecord/lib/arel/visitors/to_sql.rb
activerecord/lib/arel/visitors/to_sql.rb
+2
-1
未找到文件。
activerecord/lib/active_record/relation.rb
浏览文件 @
6d40d2d3
...
...
@@ -356,11 +356,12 @@ def update_all(updates)
stmt
.
set
Arel
.
sql
(
klass
.
sanitize_sql_for_assignment
(
updates
,
table
.
name
))
end
if
has_join_values?
||
offset_value
if
has_join_values?
@klass
.
connection
.
join_to_update
(
stmt
,
arel
,
arel_attribute
(
primary_key
))
else
stmt
.
key
=
arel_attribute
(
primary_key
)
stmt
.
take
(
arel
.
limit
)
stmt
.
offset
(
arel
.
offset
)
stmt
.
order
(
*
arel
.
orders
)
stmt
.
wheres
=
arel
.
constraints
end
...
...
@@ -484,11 +485,12 @@ def delete_all
stmt
=
Arel
::
DeleteManager
.
new
stmt
.
from
(
table
)
if
has_join_values?
||
offset_value
if
has_join_values?
@klass
.
connection
.
join_to_delete
(
stmt
,
arel
,
arel_attribute
(
primary_key
))
else
stmt
.
key
=
arel_attribute
(
primary_key
)
stmt
.
take
(
arel
.
limit
)
stmt
.
offset
(
arel
.
offset
)
stmt
.
order
(
*
arel
.
orders
)
stmt
.
wheres
=
arel
.
constraints
end
...
...
activerecord/lib/arel/nodes/delete_statement.rb
浏览文件 @
6d40d2d3
...
...
@@ -3,7 +3,7 @@
module
Arel
# :nodoc: all
module
Nodes
class
DeleteStatement
<
Arel
::
Nodes
::
Node
attr_accessor
:left
,
:right
,
:orders
,
:limit
,
:key
attr_accessor
:left
,
:right
,
:orders
,
:limit
,
:
offset
,
:
key
alias
:relation
:left
alias
:relation
=
:left
=
...
...
@@ -16,6 +16,7 @@ def initialize(relation = nil, wheres = [])
@right
=
wheres
@orders
=
[]
@limit
=
nil
@offset
=
nil
@key
=
nil
end
...
...
@@ -26,7 +27,7 @@ def initialize_copy(other)
end
def
hash
[
self
.
class
,
@left
,
@right
,
@orders
,
@limit
,
@key
].
hash
[
self
.
class
,
@left
,
@right
,
@orders
,
@limit
,
@
offset
,
@
key
].
hash
end
def
eql?
(
other
)
...
...
@@ -35,6 +36,7 @@ def eql?(other)
self
.
right
==
other
.
right
&&
self
.
orders
==
other
.
orders
&&
self
.
limit
==
other
.
limit
&&
self
.
offset
==
other
.
offset
&&
self
.
key
==
other
.
key
end
alias
:==
:eql?
...
...
activerecord/lib/arel/nodes/update_statement.rb
浏览文件 @
6d40d2d3
...
...
@@ -3,7 +3,7 @@
module
Arel
# :nodoc: all
module
Nodes
class
UpdateStatement
<
Arel
::
Nodes
::
Node
attr_accessor
:relation
,
:wheres
,
:values
,
:orders
,
:limit
,
:key
attr_accessor
:relation
,
:wheres
,
:values
,
:orders
,
:limit
,
:
offset
,
:
key
def
initialize
@relation
=
nil
...
...
@@ -11,6 +11,7 @@ def initialize
@values
=
[]
@orders
=
[]
@limit
=
nil
@offset
=
nil
@key
=
nil
end
...
...
@@ -21,7 +22,7 @@ def initialize_copy(other)
end
def
hash
[
@relation
,
@wheres
,
@values
,
@orders
,
@limit
,
@key
].
hash
[
@relation
,
@wheres
,
@values
,
@orders
,
@limit
,
@
offset
,
@
key
].
hash
end
def
eql?
(
other
)
...
...
@@ -31,6 +32,7 @@ def eql?(other)
self
.
values
==
other
.
values
&&
self
.
orders
==
other
.
orders
&&
self
.
limit
==
other
.
limit
&&
self
.
offset
==
other
.
offset
&&
self
.
key
==
other
.
key
end
alias
:==
:eql?
...
...
activerecord/lib/arel/tree_manager.rb
浏览文件 @
6d40d2d3
...
...
@@ -10,6 +10,11 @@ def take(limit)
self
end
def
offset
(
offset
)
@ast
.
offset
=
Nodes
::
Offset
.
new
(
Nodes
.
build_quoted
(
offset
))
if
offset
self
end
def
order
(
*
expr
)
@ast
.
orders
=
expr
self
...
...
activerecord/lib/arel/visitors/mysql.rb
浏览文件 @
6d40d2d3
...
...
@@ -56,18 +56,6 @@ def visit_Arel_Nodes_SelectCore(o, collector)
super
end
def
visit_Arel_Nodes_UpdateStatement
(
o
,
collector
)
collector
<<
"UPDATE "
collector
=
visit
o
.
relation
,
collector
unless
o
.
values
.
empty?
collector
<<
" SET "
collector
=
inject_join
o
.
values
,
collector
,
", "
end
collect_where_for
(
o
,
collector
)
end
def
visit_Arel_Nodes_Concat
(
o
,
collector
)
collector
<<
" CONCAT("
visit
o
.
left
,
collector
...
...
@@ -77,7 +65,23 @@ def visit_Arel_Nodes_Concat(o, collector)
collector
end
def
build_subselect
(
key
,
o
)
subselect
=
super
# Materialize subquery by adding distinct
# to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
subselect
.
distinct
unless
subselect
.
limit
||
subselect
.
offset
||
subselect
.
orders
.
any?
Nodes
::
SelectStatement
.
new
.
tap
do
|
stmt
|
core
=
stmt
.
cores
.
last
core
.
froms
=
Nodes
::
Grouping
.
new
(
subselect
).
as
(
"__active_record_temp"
)
core
.
projections
=
[
Arel
.
sql
(
quote_column_name
(
key
.
name
))]
end
end
def
collect_where_for
(
o
,
collector
)
return
super
if
o
.
offset
unless
o
.
wheres
.
empty?
collector
<<
" WHERE "
collector
=
inject_join
o
.
wheres
,
collector
,
" AND "
...
...
activerecord/lib/arel/visitors/to_sql.rb
浏览文件 @
6d40d2d3
...
...
@@ -88,6 +88,7 @@ def build_subselect(key, o)
core
.
wheres
=
o
.
wheres
core
.
projections
=
[
key
]
stmt
.
limit
=
o
.
limit
stmt
.
offset
=
o
.
offset
stmt
.
orders
=
o
.
orders
stmt
end
...
...
@@ -800,7 +801,7 @@ def inject_join(list, collector, join_str)
end
def
collect_where_for
(
o
,
collector
)
if
o
.
orders
.
empty?
&&
o
.
limit
.
nil?
if
o
.
orders
.
empty?
&&
o
.
limit
.
nil?
&&
o
.
offset
.
nil?
wheres
=
o
.
wheres
else
wheres
=
[
Nodes
::
In
.
new
(
o
.
key
,
[
build_subselect
(
o
.
key
,
o
)])]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录