diff options
author | Yves Senn <yves.senn@gmail.com> | 2012-12-02 21:24:47 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@garaio.com> | 2012-12-04 13:35:49 +0100 |
commit | 1b961765871eba76d50d463d3af6c3c5926f537a (patch) | |
tree | e45ee0a495f7f351e6f3d7822b62ab209e34132e /activerecord/lib/active_record/relation/finder_methods.rb | |
parent | dac811e8542ee7b9abb88a5839fa22dd59c7c737 (diff) | |
download | rails-1b961765871eba76d50d463d3af6c3c5926f537a.tar.gz rails-1b961765871eba76d50d463d3af6c3c5926f537a.tar.bz2 rails-1b961765871eba76d50d463d3af6c3c5926f537a.zip |
backport #8403, no intermediate AR objects when eager loading.
Closes #3313
Conflicts:
activerecord/CHANGELOG.md
activerecord/test/models/developer.rb
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 57ecabb537..cbb2f676c8 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -253,9 +253,11 @@ module ActiveRecord orders = relation.order_values.map { |val| val.presence }.compact values = @klass.connection.distinct("#{@klass.connection.quote_table_name table_name}.#{primary_key}", orders) - relation = relation.dup + relation = relation.dup.select(values) + + id_rows = @klass.connection.select_all(relation.arel, 'SQL', relation.bind_values) + ids_array = id_rows.map {|row| row[primary_key]} - ids_array = relation.select(values).collect {|row| row[primary_key]} ids_array.empty? ? raise(ThrowResult) : table[primary_key].in(ids_array) end |