diff options
author | Willian Gustavo Veiga <beberveiga@gmail.com> | 2018-10-24 20:29:13 -0300 |
---|---|---|
committer | Willian Gustavo Veiga <beberveiga@gmail.com> | 2018-10-24 20:29:13 -0300 |
commit | b217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82 (patch) | |
tree | b4f1c3c65bf98c4b62438c0c92bd5d56e1bd2c00 | |
parent | 47ef6fd2ca596a7d47bac6b584d5eced46e0d4d8 (diff) | |
download | rails-b217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82.tar.gz rails-b217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82.tar.bz2 rails-b217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82.zip |
Avoid creating an extra relation instance
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 94c42fb630..b41cbf6f48 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -250,8 +250,15 @@ module ActiveRecord # # This is short-hand for <tt>unscope(:select).select(fields)</tt>. # Note that we're unscoping the entire select statement. - def reselect(*fields) - unscope(:select).select(*fields) + def reselect(*args) + check_if_method_has_arguments!(:reselect, args) + spawn.reselect!(*args) + end + + # Same as #reselect but operates on relation in-place instead of copying. + def reselect!(*args) # :nodoc: + self.select_values = args + self end # Allows to specify a group attribute: |