diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2019-03-01 08:33:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-01 08:33:01 +0000 |
commit | 0c4bf982e80414a5437f18f988b63885359326e7 (patch) | |
tree | 95188dab2ebdd238711f6abbb5403f5d7ef83e79 /activerecord/lib | |
parent | 8189abc1f23b78e4cad3857848a1333fd77eca37 (diff) | |
parent | b217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82 (diff) | |
download | rails-0c4bf982e80414a5437f18f988b63885359326e7.tar.gz rails-0c4bf982e80414a5437f18f988b63885359326e7.tar.bz2 rails-0c4bf982e80414a5437f18f988b63885359326e7.zip |
Merge pull request #33611 from willianveiga/feature/reselect-method
Add reselect method
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index f69b85af66..f88493df8a 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -240,6 +240,27 @@ module ActiveRecord self end + # Allows you to change a previously set select statement. + # + # Post.select(:title, :body) + # # SELECT `posts.title`, `posts.body` FROM `posts` + # + # Post.select(:title, :body).reselect(:created_at) + # # SELECT `posts.created_at` FROM `posts` + # + # This is short-hand for <tt>unscope(:select).select(fields)</tt>. + # Note that we're unscoping the entire select statement. + 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: # # User.group(:name) |