From 6ca921a98cefa2bce67486f1ba2a8f52f4170d78 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 22 Dec 2010 18:05:30 -0800 Subject: use arel to compile SQL rather than build strings --- activerecord/lib/active_record/association_preload.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index 9504b00515..9ac792fe3f 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -201,11 +201,18 @@ module ActiveRecord 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| -- cgit v1.2.3