Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4b9e83af
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,发现更多精彩内容 >>
提交
4b9e83af
编写于
1月 01, 2016
作者:
R
Rafael França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22877 from kamipo/refactor_case_sensitive_comparison
Refactor `case_{sensitive|insensitive}_comparison`
上级
2746a227
b80d304f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
20 deletion
+17
-20
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+6
-8
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+4
-9
activerecord/lib/active_record/relation/where_clause_factory.rb
...record/lib/active_record/relation/where_clause_factory.rb
+1
-0
activerecord/lib/active_record/validations/uniqueness.rb
activerecord/lib/active_record/validations/uniqueness.rb
+6
-3
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
4b9e83af
...
...
@@ -391,19 +391,17 @@ def create_savepoint(name = nil)
def
release_savepoint
(
name
=
nil
)
end
def
case_sensitive_modifier
(
node
,
table_attribute
)
node
end
def
case_sensitive_comparison
(
table
,
attribute
,
column
,
value
)
table_attr
=
table
[
attribute
]
value
=
case_sensitive_modifier
(
value
,
table_attr
)
unless
value
.
nil?
table_attr
.
eq
(
value
)
if
value
.
nil?
table
[
attribute
].
eq
(
value
)
else
table
[
attribute
].
eq
(
Arel
::
Nodes
::
BindParam
.
new
)
end
end
def
case_insensitive_comparison
(
table
,
attribute
,
column
,
value
)
if
can_perform_case_insensitive_comparison_for?
(
column
)
table
[
attribute
].
lower
.
eq
(
table
.
lower
(
value
))
table
[
attribute
].
lower
.
eq
(
table
.
lower
(
Arel
::
Nodes
::
BindParam
.
new
))
else
case_sensitive_comparison
(
table
,
attribute
,
column
,
value
)
end
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
4b9e83af
...
...
@@ -752,16 +752,11 @@ def primary_keys(table_name) # :nodoc:
SQL
end
def
case_sensitive_modifier
(
node
,
table_attribute
)
node
=
Arel
::
Nodes
.
build_quoted
node
,
table_attribute
Arel
::
Nodes
::
Bin
.
new
(
node
)
end
def
case_sensitive_comparison
(
table
,
attribute
,
column
,
value
)
if
column
.
case_sensitive?
table
[
attribute
].
eq
(
value
)
else
if
value
.
nil?
||
column
.
case_sensitive?
super
else
table
[
attribute
].
eq
(
Arel
::
Nodes
::
Bin
.
new
(
Arel
::
Nodes
::
BindParam
.
new
))
end
end
...
...
@@ -769,7 +764,7 @@ def case_insensitive_comparison(table, attribute, column, value)
if
column
.
case_sensitive?
super
else
table
[
attribute
].
eq
(
value
)
table
[
attribute
].
eq
(
Arel
::
Nodes
::
BindParam
.
new
)
end
end
...
...
activerecord/lib/active_record/relation/where_clause_factory.rb
浏览文件 @
4b9e83af
...
...
@@ -22,6 +22,7 @@ def build(opts, other)
parts
=
predicate_builder
.
build_from_hash
(
attributes
)
when
Arel
::
Nodes
::
Node
parts
=
[
opts
]
binds
=
other
else
raise
ArgumentError
,
"Unsupported argument type:
#{
opts
}
(
#{
opts
.
class
}
)"
end
...
...
activerecord/lib/active_record/validations/uniqueness.rb
浏览文件 @
4b9e83af
...
...
@@ -73,15 +73,18 @@ def build_relation(klass, table, attribute, value) #:nodoc:
value
=
value
.
to_s
[
0
,
column
.
limit
]
end
value
=
Arel
::
Nodes
::
Quoted
.
new
(
value
)
comparison
=
if
!
options
[
:case_sensitive
]
&&
!
value
.
nil?
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
klass
.
connection
.
case_insensitive_comparison
(
table
,
attribute
,
column
,
value
)
else
klass
.
connection
.
case_sensitive_comparison
(
table
,
attribute
,
column
,
value
)
end
klass
.
unscoped
.
where
(
comparison
)
if
value
.
nil?
klass
.
unscoped
.
where
(
comparison
)
else
bind
=
Relation
::
QueryAttribute
.
new
(
attribute
.
to_s
,
value
,
Type
::
Value
.
new
)
klass
.
unscoped
.
where
(
comparison
,
bind
)
end
rescue
RangeError
klass
.
none
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录