Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4bc2ae0d
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 搜索 >>
提交
4bc2ae0d
编写于
2月 27, 2012
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use bind values for join columns
上级
a4e4d285
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
12 deletion
+36
-12
activerecord/lib/active_record/associations/association_scope.rb
...ecord/lib/active_record/associations/association_scope.rb
+16
-1
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
...ecord/connection_adapters/abstract/database_statements.rb
+4
-4
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+6
-1
activerecord/lib/active_record/relation/calculations.rb
activerecord/lib/active_record/relation/calculations.rb
+4
-3
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+2
-2
activerecord/lib/active_record/relation/spawn_methods.rb
activerecord/lib/active_record/relation/spawn_methods.rb
+4
-1
未找到文件。
activerecord/lib/active_record/associations/association_scope.rb
浏览文件 @
4bc2ae0d
...
...
@@ -33,6 +33,18 @@ def scope
private
def
column_for
(
table_name
,
column_name
)
columns
=
alias_tracker
.
connection
.
schema_cache
.
columns_hash
[
table_name
]
columns
[
column_name
]
end
def
bind
(
scope
,
column
,
value
)
substitute
=
alias_tracker
.
connection
.
substitute_at
(
column
,
scope
.
bind_values
.
length
)
scope
.
bind_values
+=
[[
column
,
value
]]
substitute
end
def
add_constraints
(
scope
)
tables
=
construct_tables
...
...
@@ -67,7 +79,10 @@ def add_constraints(scope)
conditions
=
self
.
conditions
[
i
]
if
reflection
==
chain
.
last
scope
=
scope
.
where
(
table
[
key
].
eq
(
owner
[
foreign_key
]))
column
=
column_for
(
table
.
table_name
,
key
.
to_s
)
bind_val
=
bind
(
scope
,
column
,
owner
[
foreign_key
])
scope
=
scope
.
where
(
table
[
key
].
eq
(
bind_val
))
#scope = scope.where(table[key].eq(owner[foreign_key]))
if
reflection
.
type
scope
=
scope
.
where
(
table
[
reflection
.
type
].
eq
(
owner
.
class
.
base_class
.
name
))
...
...
activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
浏览文件 @
4bc2ae0d
...
...
@@ -20,14 +20,14 @@ def select_all(arel, name = nil, binds = [])
# Returns a record hash with the column names as keys and column values
# as values.
def
select_one
(
arel
,
name
=
nil
)
result
=
select_all
(
arel
,
name
)
def
select_one
(
arel
,
name
=
nil
,
binds
=
[]
)
result
=
select_all
(
arel
,
name
,
binds
)
result
.
first
if
result
end
# Returns a single value from a record
def
select_value
(
arel
,
name
=
nil
)
if
result
=
select_one
(
arel
,
name
)
def
select_value
(
arel
,
name
=
nil
,
binds
=
[]
)
if
result
=
select_one
(
arel
,
name
,
binds
)
result
.
values
.
first
end
end
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
4bc2ae0d
...
...
@@ -463,7 +463,12 @@ def where_values_hash
node
.
left
.
relation
.
name
==
table_name
}
Hash
[
equalities
.
map
{
|
where
|
[
where
.
left
.
name
,
where
.
right
]
}]
binds
=
Hash
[
bind_values
.
find_all
(
&
:first
).
map
{
|
column
,
v
|
[
column
.
name
,
v
]
}]
Hash
[
equalities
.
map
{
|
where
|
name
=
where
.
left
.
name
[
name
,
binds
.
fetch
(
name
.
to_s
)
{
where
.
right
}]
}]
end
def
scope_for_create
...
...
activerecord/lib/active_record/relation/calculations.rb
浏览文件 @
4bc2ae0d
...
...
@@ -183,7 +183,7 @@ def pluck(column_name)
column_name
=
"
#{
table_name
}
.
#{
column_name
}
"
end
result
=
klass
.
connection
.
select_all
(
select
(
column_name
).
arel
)
result
=
klass
.
connection
.
select_all
(
select
(
column_name
).
arel
,
nil
,
bind_values
)
types
=
result
.
column_types
.
merge
klass
.
column_types
column
=
types
[
key
]
...
...
@@ -254,7 +254,8 @@ def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
query_builder
=
relation
.
arel
end
type_cast_calculated_value
(
@klass
.
connection
.
select_value
(
query_builder
),
column_for
(
column_name
),
operation
)
result
=
@klass
.
connection
.
select_value
(
query_builder
,
nil
,
relation
.
bind_values
)
type_cast_calculated_value
(
result
,
column_for
(
column_name
),
operation
)
end
def
execute_grouped_calculation
(
operation
,
column_name
,
distinct
)
#:nodoc:
...
...
@@ -290,7 +291,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
relation
=
except
(
:group
).
group
(
group
.
join
(
','
))
relation
.
select_values
=
select_values
calculated_data
=
@klass
.
connection
.
select_all
(
relation
)
calculated_data
=
@klass
.
connection
.
select_all
(
relation
,
nil
,
bind_values
)
if
association
key_ids
=
calculated_data
.
collect
{
|
row
|
row
[
group_aliases
.
first
]
}
...
...
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
4bc2ae0d
...
...
@@ -200,7 +200,7 @@ def exists?(id = false)
relation
=
relation
.
where
(
table
[
primary_key
].
eq
(
id
))
if
id
end
connection
.
select_value
(
relation
,
"
#{
name
}
Exists"
)
?
true
:
false
connection
.
select_value
(
relation
,
"
#{
name
}
Exists"
,
relation
.
bind_values
)
?
true
:
false
end
protected
...
...
@@ -331,7 +331,7 @@ def find_one(id)
substitute
=
connection
.
substitute_at
(
column
,
@bind_values
.
length
)
relation
=
where
(
table
[
primary_key
].
eq
(
substitute
))
relation
.
bind_values
=
[[
column
,
id
]]
relation
.
bind_values
+
=
[[
column
,
id
]]
record
=
relation
.
first
unless
record
...
...
activerecord/lib/active_record/relation/spawn_methods.rb
浏览文件 @
4bc2ae0d
...
...
@@ -22,7 +22,7 @@ def merge(r)
end
end
(
Relation
::
MULTI_VALUE_METHODS
-
[
:joins
,
:where
,
:order
]).
each
do
|
method
|
(
Relation
::
MULTI_VALUE_METHODS
-
[
:joins
,
:where
,
:order
,
:binds
]).
each
do
|
method
|
value
=
r
.
send
(
:"
#{
method
}
_values"
)
next
if
value
.
empty?
...
...
@@ -34,6 +34,8 @@ def merge(r)
merged_wheres
=
@where_values
+
r
.
where_values
merged_binds
=
(
@bind_values
+
r
.
bind_values
).
uniq
(
&
:first
)
unless
@where_values
.
empty?
# Remove duplicates, last one wins.
seen
=
Hash
.
new
{
|
h
,
table
|
h
[
table
]
=
{}
}
...
...
@@ -50,6 +52,7 @@ def merge(r)
end
merged_relation
.
where_values
=
merged_wheres
merged_relation
.
bind_values
=
merged_binds
(
Relation
::
SINGLE_VALUE_METHODS
-
[
:lock
,
:create_with
,
:reordering
]).
each
do
|
method
|
value
=
r
.
send
(
:"
#{
method
}
_value"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录