diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2011-12-17 19:50:47 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2011-12-18 10:59:24 +0300 |
commit | 109db5a55035781166f295d38a2702ce3cc83858 (patch) | |
tree | d59f9b25b5ff4240ce442ffd7d4b35fb0c4513fc /activerecord/lib/active_record | |
parent | 7bde2e2578ea67841409ab5ac951daa58e15474a (diff) | |
download | rails-109db5a55035781166f295d38a2702ce3cc83858.tar.gz rails-109db5a55035781166f295d38a2702ce3cc83858.tar.bz2 rails-109db5a55035781166f295d38a2702ce3cc83858.zip |
bypass preloading for ids_reader
when fetching ids for a collection, bypass preloading
to avoid the unnecessary performance overhead
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 12 |
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 |