Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8c71e8b1
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 搜索 >>
提交
8c71e8b1
编写于
1月 11, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lazily instantiate AR objects in order to avoid NoMethodErrors
上级
af96018c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
17 deletion
+24
-17
activerecord/lib/active_record/association_preload.rb
activerecord/lib/active_record/association_preload.rb
+14
-8
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+10
-9
未找到文件。
activerecord/lib/active_record/association_preload.rb
浏览文件 @
8c71e8b1
...
...
@@ -137,9 +137,9 @@ def add_preloaded_record_to_collection(parent_records, reflection_name, associat
end
end
def
set_association_collection_records
(
id_to_
record
_map
,
reflection_name
,
associated_records
,
key
)
def
set_association_collection_records
(
id_to_
parent
_map
,
reflection_name
,
associated_records
,
key
)
associated_records
.
each
do
|
associated_record
|
parent_records
=
id_to_
record
_map
[
associated_record
[
key
].
to_s
]
parent_records
=
id_to_
parent
_map
[
associated_record
[
key
].
to_s
]
add_preloaded_records_to_collection
(
parent_records
,
reflection_name
,
associated_record
)
end
end
...
...
@@ -199,7 +199,6 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
right
=
Arel
::
Table
.
new
(
options
[
:join_table
]).
alias
(
't0'
)
join_condition
=
left
[
reflection
.
klass
.
primary_key
].
eq
(
right
[
reflection
.
association_foreign_key
])
...
...
@@ -221,17 +220,24 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
custom_conditions
=
append_conditions
(
reflection
,
preload_options
)
all_associated_records
=
associated_records
(
ids
)
do
|
some_ids
|
klass
=
associated_records_proxy
.
klass
associated_records
(
ids
)
{
|
some_ids
|
method
=
in_or_equal
(
some_ids
)
conditions
=
right
[
reflection
.
foreign_key
].
send
(
*
method
)
conditions
=
custom_conditions
.
inject
(
conditions
)
do
|
ast
,
cond
|
ast
.
and
cond
end
associated_records_proxy
.
where
(
conditions
).
to_a
end
set_association_collection_records
(
id_to_record_map
,
reflection
.
name
,
all_associated_records
,
'the_parent_record_id'
)
relation
=
associated_records_proxy
.
where
(
conditions
)
klass
.
connection
.
select_all
(
relation
.
arel
.
to_sql
,
'SQL'
,
relation
.
bind_values
)
}.
map!
{
|
row
|
parent_records
=
id_to_record_map
[
row
[
'the_parent_record_id'
].
to_s
]
associated_record
=
klass
.
instantiate
row
add_preloaded_records_to_collection
(
parent_records
,
reflection
.
name
,
associated_record
)
associated_record
}
end
def
preload_has_one_association
(
records
,
reflection
,
preload_options
=
{})
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
8c71e8b1
...
...
@@ -880,6 +880,16 @@ def _load(data)
record
end
# Finder methods must instantiate through this method to work with the
# single-table inheritance model that makes it possible to create
# objects of different types from the same table.
def
instantiate
(
record
)
# :nodoc:
model
=
find_sti_class
(
record
[
inheritance_column
]).
allocate
model
.
init_with
(
'attributes'
=>
record
)
model
end
private
def
relation
#:nodoc:
...
...
@@ -892,15 +902,6 @@ def relation #:nodoc:
end
end
# Finder methods must instantiate through this method to work with the
# single-table inheritance model that makes it possible to create
# objects of different types from the same table.
def
instantiate
(
record
)
model
=
find_sti_class
(
record
[
inheritance_column
]).
allocate
model
.
init_with
(
'attributes'
=>
record
)
model
end
def
find_sti_class
(
type_name
)
if
type_name
.
blank?
||
!
columns_hash
.
include?
(
inheritance_column
)
self
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录