diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 15:39:10 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 15:39:10 -0700 |
commit | c6fbbbc17440b6629fc41fef1a6fc80a1830f982 (patch) | |
tree | 78090bddc1f3f90d56b3459578bd43b30b2c9e80 /activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb | |
parent | 18dccdccf75e4084718622f578a1ff98f2da6955 (diff) | |
download | rails-c6fbbbc17440b6629fc41fef1a6fc80a1830f982.tar.gz rails-c6fbbbc17440b6629fc41fef1a6fc80a1830f982.tar.bz2 rails-c6fbbbc17440b6629fc41fef1a6fc80a1830f982.zip |
push `run` up to preload
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb index 87992a70e8..48ae99819b 100644 --- a/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb @@ -7,6 +7,7 @@ module ActiveRecord def initialize(klass, records, reflection, preload_options) super @join_table = Arel::Table.new(reflection.join_table).alias('t0') + @records_by_owner = nil end # Unlike the other associations, we want to get a raw array of rows so that we can @@ -34,8 +35,10 @@ module ActiveRecord # actual records, ensuring that we don't create more than one instances of the same # record def associated_records_by_owner + return @records_by_owner if @records_by_owner + records = {} - super.each_value do |rows| + @records_by_owner = super.each_value do |rows| rows.map! { |row| records[row[klass.primary_key]] ||= klass.instantiate(row) } end end |