Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b35873a5
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,发现更多精彩内容 >>
提交
b35873a5
编写于
1月 02, 2010
作者:
P
Pratik Naik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename Model.arel_table to Model.active_relation
上级
d2c4b3b6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
29 addition
and
29 deletion
+29
-29
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+2
-2
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+13
-13
activerecord/lib/active_record/calculations.rb
activerecord/lib/active_record/calculations.rb
+2
-2
activerecord/lib/active_record/locking/optimistic.rb
activerecord/lib/active_record/locking/optimistic.rb
+4
-4
activerecord/lib/active_record/named_scope.rb
activerecord/lib/active_record/named_scope.rb
+1
-1
activerecord/lib/active_record/relation/calculation_methods.rb
...erecord/lib/active_record/relation/calculation_methods.rb
+2
-2
activerecord/lib/active_record/relation/predicate_builder.rb
activerecord/lib/active_record/relation/predicate_builder.rb
+5
-5
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
b35873a5
...
...
@@ -1706,7 +1706,7 @@ def select_all_rows(options, join_dependency)
def
construct_finder_arel_with_included_associations
(
options
,
join_dependency
)
scope
=
scope
(
:find
)
relation
=
a
rel_table
relation
=
a
ctive_relation
for
association
in
join_dependency
.
join_associations
relation
=
association
.
join_relation
(
relation
)
...
...
@@ -1751,7 +1751,7 @@ def select_limited_ids_array(options, join_dependency)
def
construct_finder_sql_for_association_limiting
(
options
,
join_dependency
)
scope
=
scope
(
:find
)
relation
=
a
rel_table
relation
=
a
ctive_relation
for
association
in
join_dependency
.
join_associations
relation
=
association
.
join_relation
(
relation
)
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
b35873a5
...
...
@@ -816,7 +816,7 @@ def update(id, attributes)
# # Delete multiple rows
# Todo.delete([2,3,4])
def
delete
(
id_or_array
)
a
rel_table
.
where
(
construct_conditions
(
nil
,
scope
(
:find
))).
delete
(
id_or_array
)
a
ctive_relation
.
where
(
construct_conditions
(
nil
,
scope
(
:find
))).
delete
(
id_or_array
)
end
# Destroy an object (or multiple objects) that has the given id, the object is instantiated first,
...
...
@@ -873,7 +873,7 @@ def destroy(id)
def
update_all
(
updates
,
conditions
=
nil
,
options
=
{})
scope
=
scope
(
:find
)
relation
=
a
rel_table
relation
=
a
ctive_relation
if
conditions
=
construct_conditions
(
conditions
,
scope
)
relation
=
relation
.
where
(
Arel
::
SqlLiteral
.
new
(
conditions
))
...
...
@@ -938,7 +938,7 @@ def destroy_all(conditions = nil)
# Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent
# associations or call your <tt>before_*</tt> or +after_destroy+ callbacks, use the +destroy_all+ method instead.
def
delete_all
(
conditions
=
nil
)
a
rel_table
.
where
(
construct_conditions
(
conditions
,
scope
(
:find
))).
delete_all
a
ctive_relation
.
where
(
construct_conditions
(
conditions
,
scope
(
:find
))).
delete_all
end
# Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part.
...
...
@@ -1392,7 +1392,7 @@ def column_methods_hash #:nodoc:
def
reset_column_information
undefine_attribute_methods
@column_names
=
@columns
=
@columns_hash
=
@content_columns
=
@dynamic_methods_hash
=
@inheritance_column
=
nil
@a
rel_table
=
@active_relation_engine
=
nil
@a
ctive_relation
=
@active_relation_engine
=
nil
end
def
reset_column_information_and_inheritable_attributes_for_all_subclasses
#:nodoc:
...
...
@@ -1505,8 +1505,8 @@ def merge_conditions(*conditions)
"(
#{
segments
.
join
(
') AND ('
)
}
)"
unless
segments
.
empty?
end
def
a
rel_table
@a
rel_table
||=
Relation
.
new
(
self
,
active_relation_table
)
def
a
ctive_relation
@a
ctive_relation
||=
Relation
.
new
(
self
,
active_relation_table
)
end
def
active_relation_table
(
table_name_alias
=
nil
)
...
...
@@ -1570,7 +1570,7 @@ def default_select(qualified)
def
construct_finder_arel
(
options
=
{},
scope
=
scope
(
:find
))
validate_find_options
(
options
)
relation
=
a
rel_table
.
relation
=
a
ctive_relation
.
joins
(
construct_join
(
options
[
:joins
],
scope
)).
where
(
construct_conditions
(
options
[
:conditions
],
scope
)).
select
(
options
[
:select
]
||
(
scope
&&
scope
[
:select
])
||
default_select
(
options
[
:joins
]
||
(
scope
&&
scope
[
:joins
]))).
...
...
@@ -1671,7 +1671,7 @@ def merge_joins(*joins)
def
build_association_joins
(
joins
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
self
,
joins
,
nil
)
relation
=
a
rel_table
.
relation
relation
=
a
ctive_relation
.
relation
join_dependency
.
join_associations
.
map
{
|
association
|
if
(
association_relation
=
association
.
relation
).
is_a?
(
Array
)
[
Arel
::
InnerJoin
.
new
(
relation
,
association_relation
.
first
,
association
.
association_join
.
first
).
joins
(
relation
),
...
...
@@ -2314,7 +2314,7 @@ def delete
# be made (since they can't be persisted).
def
destroy
unless
new_record?
self
.
class
.
a
rel_table
.
where
(
self
.
class
.
arel_table
[
self
.
class
.
primary_key
].
eq
(
id
)).
delete_all
self
.
class
.
a
ctive_relation
.
where
(
self
.
class
.
active_relation
[
self
.
class
.
primary_key
].
eq
(
id
)).
delete_all
end
@destroyed
=
true
...
...
@@ -2601,7 +2601,7 @@ def create_or_update
def
update
(
attribute_names
=
@attributes
.
keys
)
attributes_with_values
=
arel_attributes_values
(
false
,
false
,
attribute_names
)
return
0
if
attributes_with_values
.
empty?
self
.
class
.
a
rel_table
.
where
(
self
.
class
.
arel_table
[
self
.
class
.
primary_key
].
eq
(
id
)).
update
(
attributes_with_values
)
self
.
class
.
a
ctive_relation
.
where
(
self
.
class
.
active_relation
[
self
.
class
.
primary_key
].
eq
(
id
)).
update
(
attributes_with_values
)
end
# Creates a record with values matching those of the instance attributes
...
...
@@ -2614,9 +2614,9 @@ def create
attributes_values
=
arel_attributes_values
new_id
=
if
attributes_values
.
empty?
self
.
class
.
a
rel_table
.
insert
connection
.
empty_insert_statement_value
self
.
class
.
a
ctive_relation
.
insert
connection
.
empty_insert_statement_value
else
self
.
class
.
a
rel_table
.
insert
attributes_values
self
.
class
.
a
ctive_relation
.
insert
attributes_values
end
self
.
id
||=
new_id
...
...
@@ -2711,7 +2711,7 @@ def arel_attributes_values(include_primary_key = true, include_readonly_attribut
if
value
&&
((
self
.
class
.
serialized_attributes
.
has_key?
(
name
)
&&
(
value
.
acts_like?
(
:date
)
||
value
.
acts_like?
(
:time
)))
||
value
.
is_a?
(
Hash
)
||
value
.
is_a?
(
Array
))
value
=
value
.
to_yaml
end
attrs
[
self
.
class
.
a
rel_table
[
name
]]
=
value
attrs
[
self
.
class
.
a
ctive_relation
[
name
]]
=
value
end
end
end
...
...
activerecord/lib/active_record/calculations.rb
浏览文件 @
b35873a5
...
...
@@ -162,7 +162,7 @@ def construct_calculation_arel(options = {})
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
self
,
includes
,
construct_join
(
options
[
:joins
],
scope
))
construct_calculation_arel_with_included_associations
(
options
,
join_dependency
)
else
a
rel_table
.
a
ctive_relation
.
joins
(
construct_join
(
options
[
:joins
],
scope
)).
from
((
scope
&&
scope
[
:from
])
||
options
[
:from
]).
where
(
construct_conditions
(
options
[
:conditions
],
scope
)).
...
...
@@ -178,7 +178,7 @@ def construct_calculation_arel(options = {})
def
construct_calculation_arel_with_included_associations
(
options
,
join_dependency
)
scope
=
scope
(
:find
)
relation
=
a
rel_table
relation
=
a
ctive_relation
for
association
in
join_dependency
.
join_associations
relation
=
association
.
join_relation
(
relation
)
...
...
activerecord/lib/active_record/locking/optimistic.rb
浏览文件 @
b35873a5
...
...
@@ -78,11 +78,11 @@ def update_with_lock(attribute_names = @attributes.keys) #:nodoc:
attribute_names
.
uniq!
begin
arel_table
=
self
.
class
.
arel_table
relation
=
self
.
class
.
active_relation
affected_rows
=
arel_table
.
where
(
arel_table
[
self
.
class
.
primary_key
].
eq
(
quoted_id
).
and
(
arel_table
[
self
.
class
.
locking_column
].
eq
(
quote_value
(
previous_value
))
affected_rows
=
relation
.
where
(
relation
[
self
.
class
.
primary_key
].
eq
(
quoted_id
).
and
(
relation
[
self
.
class
.
locking_column
].
eq
(
quote_value
(
previous_value
))
)
).
update
(
arel_attributes_values
(
false
,
false
,
attribute_names
))
...
...
activerecord/lib/active_record/named_scope.rb
浏览文件 @
b35873a5
...
...
@@ -27,7 +27,7 @@ def scoped(options = {}, &block)
Scope
.
new
(
self
,
options
,
&
block
)
else
unless
scoped?
(
:find
)
finder_needs_type_condition?
?
a
rel_table
.
where
(
type_condition
)
:
arel_table
.
spawn
finder_needs_type_condition?
?
a
ctive_relation
.
where
(
type_condition
)
:
active_relation
.
spawn
else
construct_finder_arel_with_includes
end
...
...
activerecord/lib/active_record/relation/calculation_methods.rb
浏览文件 @
b35873a5
...
...
@@ -53,7 +53,7 @@ def calculate(operation, column_name, options = {})
def
execute_simple_calculation
(
operation
,
column_name
,
distinct
)
#:nodoc:
column
=
if
@klass
.
column_names
.
include?
(
column_name
.
to_s
)
Arel
::
Attribute
.
new
(
@klass
.
a
rel_table
,
column_name
)
Arel
::
Attribute
.
new
(
@klass
.
a
ctive_relation
,
column_name
)
else
Arel
::
SqlLiteral
.
new
(
column_name
==
:all
?
"*"
:
column_name
.
to_s
)
end
...
...
@@ -77,7 +77,7 @@ def execute_grouped_calculation(operation, column_name) #:nodoc:
select_statement
=
if
operation
==
'count'
&&
column_name
==
:all
"COUNT(*) AS count_all"
else
Arel
::
Attribute
.
new
(
@klass
.
a
rel_table
,
column_name
).
send
(
operation
).
as
(
aggregate_alias
).
to_sql
Arel
::
Attribute
.
new
(
@klass
.
a
ctive_relation
,
column_name
).
send
(
operation
).
as
(
aggregate_alias
).
to_sql
end
select_statement
<<
",
#{
group_field
}
AS
#{
group_alias
}
"
...
...
activerecord/lib/active_record/relation/predicate_builder.rb
浏览文件 @
b35873a5
...
...
@@ -7,20 +7,20 @@ def initialize(engine)
def
build_from_hash
(
attributes
,
default_table
)
predicates
=
attributes
.
map
do
|
column
,
value
|
arel_
table
=
default_table
table
=
default_table
if
value
.
is_a?
(
Hash
)
arel_table
=
Arel
::
Table
.
new
(
column
,
@engine
)
build_from_hash
(
value
,
arel_
table
)
table
=
Arel
::
Table
.
new
(
column
,
:engine
=>
@engine
)
build_from_hash
(
value
,
table
)
else
column
=
column
.
to_s
if
column
.
include?
(
'.'
)
table_name
,
column
=
column
.
split
(
'.'
,
2
)
arel_table
=
Arel
::
Table
.
new
(
table_name
,
@engine
)
table
=
Arel
::
Table
.
new
(
table_name
,
:engine
=>
@engine
)
end
attribute
=
arel_table
[
column
]
||
Arel
::
Attribute
.
new
(
arel_
table
,
column
.
to_sym
)
attribute
=
table
[
column
]
||
Arel
::
Attribute
.
new
(
table
,
column
.
to_sym
)
case
value
when
Array
,
ActiveRecord
::
Associations
::
AssociationCollection
,
ActiveRecord
::
NamedScope
::
Scope
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录