Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
31d10187
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,发现更多精彩内容 >>
提交
31d10187
编写于
1月 02, 2011
作者:
J
Jon Leighton
提交者:
Aaron Patterson
1月 03, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the association directly in other places too
上级
3103296a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
20 deletion
+13
-20
activerecord/lib/active_record/associations/association_collection.rb
.../lib/active_record/associations/association_collection.rb
+2
-5
activerecord/lib/active_record/associations/has_many_association.rb
...rd/lib/active_record/associations/has_many_association.rb
+2
-4
activerecord/lib/active_record/associations/has_one_association.rb
...ord/lib/active_record/associations/has_one_association.rb
+9
-11
未找到文件。
activerecord/lib/active_record/associations/association_collection.rb
浏览文件 @
31d10187
...
...
@@ -155,14 +155,13 @@ def count(column_name = nil, options = {})
@reflection
.
klass
.
count_by_sql
(
custom_counter_sql
)
else
if
@reflection
.
options
[
:uniq
]
# This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL.
column_name
=
"
#{
@reflection
.
quoted_table_name
}
.
#{
@reflection
.
klass
.
primary_key
}
"
unless
column_name
options
.
merge!
(
:distinct
=>
true
)
end
value
=
@reflection
.
klass
.
send
(
:with_scope
,
@scope
)
{
@reflection
.
klass
.
count
(
column_name
,
options
)
}
value
=
scoped
.
count
(
column_name
,
options
)
limit
=
@reflection
.
options
[
:limit
]
offset
=
@reflection
.
options
[
:offset
]
...
...
@@ -469,9 +468,7 @@ def create_record(attrs, &block)
ensure_owner_is_persisted!
transaction
do
with_scope
(
:create
=>
@scope
[
:create
].
merge
(
scoped
.
scope_for_create
))
do
build_record
(
attrs
,
&
block
)
end
scoped
.
scoping
{
build_record
(
attrs
,
&
block
)
}
end
end
...
...
activerecord/lib/active_record/associations/has_many_association.rb
浏览文件 @
31d10187
...
...
@@ -26,7 +26,7 @@ def count_records
elsif
@reflection
.
options
[
:counter_sql
]
||
@reflection
.
options
[
:finder_sql
]
@reflection
.
klass
.
count_by_sql
(
custom_counter_sql
)
else
@reflection
.
klass
.
count
(
@scope
[
:find
].
slice
(
:conditions
,
:joins
,
:include
))
scoped
.
count
end
# If there's nothing in the database and @target has no new records
...
...
@@ -61,9 +61,7 @@ def delete_records(records)
updates
=
{
@reflection
.
foreign_key
=>
nil
}
conditions
=
{
@reflection
.
association_primary_key
=>
records
.
map
{
|
r
|
r
.
id
}
}
with_scope
(
@scope
)
do
@reflection
.
klass
.
update_all
(
updates
,
conditions
)
end
scoped
.
where
(
conditions
).
update_all
(
updates
)
end
if
has_cached_counter?
&&
@reflection
.
options
[
:dependent
]
!=
:destroy
...
...
activerecord/lib/active_record/associations/has_one_association.rb
浏览文件 @
31d10187
...
...
@@ -65,17 +65,17 @@ def replace(obj, dont_save = false)
private
def
find_target
options
=
@reflection
.
options
.
dup
.
slice
(
:select
,
:order
,
:include
,
:readonly
)
the_target
=
with_scope
(
:find
=>
@scope
[
:find
])
do
@reflection
.
klass
.
find
(
:first
,
options
)
end
set_inverse_instance
(
the_target
)
the_target
scoped
.
first
.
tap
{
|
record
|
set_inverse_instance
(
record
)
}
end
def
construct_find_scope
{
:conditions
=>
construct_conditions
}
{
:conditions
=>
construct_conditions
,
:select
=>
@reflection
.
options
[
:select
],
:include
=>
@reflection
.
options
[
:include
],
:readonly
=>
@reflection
.
options
[
:readonly
],
:order
=>
@reflection
.
options
[
:order
]
}
end
def
construct_create_scope
...
...
@@ -87,9 +87,7 @@ def new_record(replace_existing)
# instance. Otherwise, if the target has not previously been loaded
# elsewhere, the instance we create will get orphaned.
load_target
if
replace_existing
record
=
@reflection
.
klass
.
send
(
:with_scope
,
:create
=>
@scope
[
:create
])
do
yield
@reflection
end
record
=
scoped
.
scoping
{
yield
@reflection
}
if
replace_existing
replace
(
record
,
true
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录