Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f0f6b7fb
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,发现更多精彩内容 >>
提交
f0f6b7fb
编写于
9月 10, 2010
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding not equal node, column names are expected to be symbols
上级
1ba8ac08
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
55 addition
and
6 deletion
+55
-6
lib/arel/attributes/attribute.rb
lib/arel/attributes/attribute.rb
+4
-0
lib/arel/compatibility/wheres.rb
lib/arel/compatibility/wheres.rb
+4
-0
lib/arel/nodes.rb
lib/arel/nodes.rb
+1
-0
lib/arel/nodes/not_equal.rb
lib/arel/nodes/not_equal.rb
+6
-0
lib/arel/nodes/table_alias.rb
lib/arel/nodes/table_alias.rb
+1
-1
lib/arel/table.rb
lib/arel/table.rb
+2
-2
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+10
-1
spec/arel/attributes/attribute_spec.rb
spec/arel/attributes/attribute_spec.rb
+25
-0
spec/arel/table_spec.rb
spec/arel/table_spec.rb
+2
-2
未找到文件。
lib/arel/attributes/attribute.rb
浏览文件 @
f0f6b7fb
module
Arel
module
Attributes
class
Attribute
<
Struct
.
new
:relation
,
:name
,
:column
def
not_eq
other
Nodes
::
NotEqual
.
new
self
,
other
end
def
eq
other
Nodes
::
Equality
.
new
self
,
other
end
...
...
lib/arel/compatibility/wheres.rb
浏览文件 @
f0f6b7fb
...
...
@@ -8,6 +8,10 @@ module Value # :nodoc:
def
value
visitor
.
accept
self
end
def
name
super
.
to_sym
end
end
def
initialize
engine
,
collection
...
...
lib/arel/nodes.rb
浏览文件 @
f0f6b7fb
require
'arel/nodes/binary'
require
'arel/nodes/equality'
require
'arel/nodes/not_equal'
require
'arel/nodes/assignment'
require
'arel/nodes/or'
require
'arel/nodes/and'
...
...
lib/arel/nodes/not_equal.rb
0 → 100644
浏览文件 @
f0f6b7fb
module
Arel
module
Nodes
class
NotEqual
<
Arel
::
Nodes
::
Binary
end
end
end
lib/arel/nodes/table_alias.rb
浏览文件 @
f0f6b7fb
...
...
@@ -12,7 +12,7 @@ def initialize name, relation
end
def
[]
name
name
=
name
.
to_s
name
=
name
.
to_s
ym
columns
.
find
{
|
column
|
column
.
name
==
name
}
end
end
...
...
lib/arel/table.rb
浏览文件 @
f0f6b7fb
...
...
@@ -73,12 +73,12 @@ def having expr
def
columns
@columns
||=
@engine
.
connection
.
columns
(
@name
,
"
#{
@name
}
Columns"
).
map
do
|
column
|
Attributes
.
for
(
column
).
new
self
,
column
.
name
,
column
Attributes
.
for
(
column
).
new
self
,
column
.
name
.
to_sym
,
column
end
end
def
[]
name
name
=
name
.
to_s
name
=
name
.
to_s
ym
columns
.
find
{
|
column
|
column
.
name
==
name
}
end
end
...
...
lib/arel/visitors/to_sql.rb
浏览文件 @
f0f6b7fb
...
...
@@ -159,7 +159,6 @@ def visit_Arel_Nodes_Assignment o
def
visit_Arel_Nodes_Equality
o
right
=
o
.
right
# FIXME: maybe we should visit NilClass?
if
right
.
nil?
"
#{
visit
o
.
left
}
IS NULL"
else
...
...
@@ -167,6 +166,16 @@ def visit_Arel_Nodes_Equality o
end
end
def
visit_Arel_Nodes_NotEqual
o
right
=
o
.
right
if
right
.
nil?
"
#{
visit
o
.
left
}
IS NOT NULL"
else
"
#{
visit
o
.
left
}
!=
#{
visit
right
}
"
end
end
def
visit_Arel_Nodes_UnqualifiedColumn
o
"
#{
quote_column_name
o
.
name
}
"
end
...
...
spec/arel/attributes/attribute_spec.rb
浏览文件 @
f0f6b7fb
...
...
@@ -3,6 +3,31 @@
module
Arel
module
Attributes
describe
'attribute'
do
describe
'#not_eq'
do
it
'should create a NotEqual node'
do
relation
=
Table
.
new
(
:users
)
relation
[
:id
].
not_eq
(
10
).
should
be_kind_of
Nodes
::
NotEqual
end
it
'should generate != in sql'
do
relation
=
Table
.
new
(
:users
)
mgr
=
relation
.
project
relation
[
:id
]
mgr
.
where
relation
[
:id
].
not_eq
(
10
)
mgr
.
to_sql
.
should
be_like
%{
SELECT "users"."id" FROM "users" WHERE "users"."id" != 10
}
end
it
'should handle nil'
do
relation
=
Table
.
new
(
:users
)
mgr
=
relation
.
project
relation
[
:id
]
mgr
.
where
relation
[
:id
].
not_eq
(
nil
)
mgr
.
to_sql
.
should
be_like
%{
SELECT "users"."id" FROM "users" WHERE "users"."id" IS NOT NULL
}
end
end
describe
'#gt'
do
it
'should create a GreaterThan node'
do
relation
=
Table
.
new
(
:users
)
...
...
spec/arel/table_spec.rb
浏览文件 @
f0f6b7fb
...
...
@@ -120,7 +120,7 @@ module Arel
it
'returns a list of columns'
do
columns
=
@relation
.
columns
check
columns
.
length
.
should
==
2
columns
.
map
{
|
x
|
x
.
name
}.
sort
.
should
==
%w{ name id }
.
sort
columns
.
map
{
|
x
|
x
.
name
.
to_s
}.
sort
.
should
==
%w{ name id }
.
sort
end
end
...
...
@@ -136,7 +136,7 @@ module Arel
describe
'when given a'
,
Symbol
do
it
"manufactures an attribute if the symbol names an attribute within the relation"
do
column
=
@relation
[
:id
]
check
column
.
name
.
should
==
'id'
check
column
.
name
.
should
==
:id
column
.
should
be_kind_of
Attributes
::
Integer
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录