From 00c50c2b5966fa1d719c8a58564811c672a0e8c6 Mon Sep 17 00:00:00 2001 From: Willian Gustavo Veiga Date: Mon, 13 Aug 2018 22:18:53 -0300 Subject: Add reselect method --- activerecord/lib/active_record/relation/query_methods.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 52405f21a1..74103d6cdd 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -240,6 +240,20 @@ 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 unscope(:select).select(fields). + # Note that we're unscoping the entire select statement. + def reselect(*fields) + unscope(:select).select(*fields) + end + # Allows to specify a group attribute: # # User.group(:name) -- cgit v1.2.3