aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-22 18:05:30 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-22 18:23:37 -0800
commit6ca921a98cefa2bce67486f1ba2a8f52f4170d78 (patch)
treef18b4d0e4b3684ac5d11bfe30212969e523fa44b /activerecord
parent2de9b858a09e735fa4e7705e929f945947e68dae (diff)
downloadrails-6ca921a98cefa2bce67486f1ba2a8f52f4170d78.tar.gz
rails-6ca921a98cefa2bce67486f1ba2a8f52f4170d78.tar.bz2
rails-6ca921a98cefa2bce67486f1ba2a8f52f4170d78.zip
use arel to compile SQL rather than build strings
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/association_preload.rb9
1 files changed, 8 insertions, 1 deletions
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|