提交 6ca921a9 编写于 作者: A Aaron Patterson

use arel to compile SQL rather than build strings

上级 2de9b858
......@@ -201,11 +201,18 @@ def preload_has_and_belongs_to_many_association(records, reflection, preload_opt
right[reflection.association_foreign_key])
join = left.create_join(right, left.create_on(condition))
select = [
# FIXME: options[:select] is always nil in the tests. Do we really
# need it?
options[:select] || left[Arel.star],
right[reflection.primary_key_name].as(
Arel.sql('the_parent_record_id'))
]
associated_records_proxy = reflection.klass.unscoped.
includes(options[:include]).
joins(join).
select("#{options[:select] || table_name+'.*'}, t0.#{reflection.primary_key_name} as the_parent_record_id").
select(select).
order(options[:order])
all_associated_records = associated_records(ids) do |some_ids|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册