diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
commit | efd0bd3b7390ebb8526b981169025f2860f6a113 (patch) | |
tree | 1cb3bcd8f9534f64e8a764af1010ce65303b42b0 /activerecord/lib/active_record/association_preload.rb | |
parent | f4571e3617ccd9cc9e5ee9f7431066bd80395e22 (diff) | |
parent | 8ff2fb6f3aa6140f5a8bd018d5919a8a1e707cda (diff) | |
download | rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.gz rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.bz2 rails-efd0bd3b7390ebb8526b981169025f2860f6a113.zip |
Merge remote branch 'mainstream/master'
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r-- | activerecord/lib/active_record/association_preload.rb | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb index a43c4d09d6..a5b06460fe 100644 --- a/activerecord/lib/active_record/association_preload.rb +++ b/activerecord/lib/active_record/association_preload.rb @@ -187,13 +187,12 @@ module ActiveRecord conditions = "t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}" conditions << append_conditions(reflection, preload_options) - associated_records = reflection.klass.with_exclusive_scope do - reflection.klass.where([conditions, ids]). + associated_records = reflection.klass.unscoped.where([conditions, ids]). includes(options[:include]). joins("INNER JOIN #{connection.quote_table_name options[:join_table]} t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}"). select("#{options[:select] || table_name+'.*'}, t0.#{reflection.primary_key_name} as the_parent_record_id"). order(options[:order]).to_a - end + set_association_collection_records(id_to_record_map, reflection.name, associated_records, 'the_parent_record_id') end @@ -341,9 +340,7 @@ module ActiveRecord conditions = "#{table_name}.#{connection.quote_column_name(primary_key)} #{in_or_equals_for_ids(ids)}" conditions << append_conditions(reflection, preload_options) - associated_records = klass.with_exclusive_scope do - klass.where([conditions, ids]).apply_finder_options(options.slice(:include, :select, :joins, :order)).to_a - end + associated_records = klass.unscoped.where([conditions, ids]).apply_finder_options(options.slice(:include, :select, :joins, :order)).to_a set_association_single_records(id_map, reflection.name, associated_records, primary_key) end @@ -362,14 +359,16 @@ module ActiveRecord conditions << append_conditions(reflection, preload_options) - reflection.klass.with_exclusive_scope do - reflection.klass.select(preload_options[:select] || options[:select] || "#{table_name}.*"). - includes(preload_options[:include] || options[:include]). - where([conditions, ids]). - joins(options[:joins]). - group(preload_options[:group] || options[:group]). - order(preload_options[:order] || options[:order]) - end + find_options = { + :select => preload_options[:select] || options[:select] || "#{table_name}.*", + :include => preload_options[:include] || options[:include], + :conditions => [conditions, ids], + :joins => options[:joins], + :group => preload_options[:group] || options[:group], + :order => preload_options[:order] || options[:order] + } + + reflection.klass.unscoped.apply_finder_options(find_options).to_a end |