aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-18 09:42:15 -0800
committerJon Leighton <j@jonathanleighton.com>2011-12-18 09:42:15 -0800
commitde2306f10cc8c0f91bf9fe3ef5c7e3daee9035f6 (patch)
tree3ddfb5e64b6069720a4ce9d840ed5d5a7d029c7f /activerecord/lib
parent81c67c1441c5aa86c92b5db87cbbc7ca1cbd8a44 (diff)
parent109db5a55035781166f295d38a2702ce3cc83858 (diff)
downloadrails-de2306f10cc8c0f91bf9fe3ef5c7e3daee9035f6.tar.gz
rails-de2306f10cc8c0f91bf9fe3ef5c7e3daee9035f6.tar.bz2
rails-de2306f10cc8c0f91bf9fe3ef5c7e3daee9035f6.zip
Merge pull request #4014 from lest/bypass-preloading-for-ids-reader
bypass preloading for ids_reader
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 207080973c..fe9f30bd2a 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -49,10 +49,18 @@ module ActiveRecord
end
else
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
+ relation = scoped
- scoped.select(column).map! do |record|
- record.send(reflection.association_primary_key)
+ including = (relation.eager_load_values + relation.includes_values).uniq
+
+ if including.any?
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(reflection.klass, including, [])
+ relation = join_dependency.join_associations.inject(relation) do |r, association|
+ association.join_relation(r)
+ end
end
+
+ relation.uniq.pluck(column)
end
end