aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/association_preload.rb
diff options
context:
space:
mode:
authorrick <technoweenie@gmail.com>2008-07-16 14:20:15 -0700
committerrick <technoweenie@gmail.com>2008-07-16 14:20:15 -0700
commit0a6d75dedd79407376aae1f01302164dfd3e44b6 (patch)
treedfef7e73b3b19a65895651c82cb6e0b727394eab /activerecord/lib/active_record/association_preload.rb
parenta14cedc7797aef4ccd9da46ed73e36d730392814 (diff)
parentfc89a951933638b051bb1f9e1339ee6ae7c94cda (diff)
downloadrails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.gz
rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.bz2
rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.zip
merge with local tweaks
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r--activerecord/lib/active_record/association_preload.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 49f5270396..174ec95de2 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -188,7 +188,6 @@ module ActiveRecord
through_records
end
- # FIXME: quoting
def preload_belongs_to_association(records, reflection, preload_options={})
options = reflection.options
primary_key_name = reflection.primary_key_name
@@ -227,9 +226,19 @@ module ActiveRecord
table_name = klass.quoted_table_name
primary_key = klass.primary_key
- conditions = "#{table_name}.#{primary_key} IN (?)"
+ conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} IN (?)"
conditions << append_conditions(options, preload_options)
- associated_records = klass.find(:all, :conditions => [conditions, id_map.keys.uniq],
+ column_type = klass.columns.detect{|c| c.name == primary_key}.type
+ ids = id_map.keys.uniq.map do |id|
+ if column_type == :integer
+ id.to_i
+ elsif column_type == :float
+ id.to_f
+ else
+ id
+ end
+ end
+ associated_records = klass.find(:all, :conditions => [conditions, ids],
:include => options[:include],
:select => options[:select],
:joins => options[:joins],