diff options
author | Willian Gustavo Veiga <beberveiga@gmail.com> | 2018-08-13 22:18:53 -0300 |
---|---|---|
committer | Willian Gustavo Veiga <willian.veiga@tnh.health> | 2018-08-13 22:19:39 -0300 |
commit | 00c50c2b5966fa1d719c8a58564811c672a0e8c6 (patch) | |
tree | 9d1fc5763be1e3690884310e1bccb054abe3d860 /activerecord/lib/active_record | |
parent | 3000c1490565b3a21376d6444cb6fe24dfe4e383 (diff) | |
download | rails-00c50c2b5966fa1d719c8a58564811c672a0e8c6.tar.gz rails-00c50c2b5966fa1d719c8a58564811c672a0e8c6.tar.bz2 rails-00c50c2b5966fa1d719c8a58564811c672a0e8c6.zip |
Add reselect method
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 14 |
1 files changed, 14 insertions, 0 deletions
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 <tt>unscope(:select).select(fields)</tt>. + # 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) |