aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2019-03-01 08:33:01 +0000
committerGitHub <noreply@github.com>2019-03-01 08:33:01 +0000
commit0c4bf982e80414a5437f18f988b63885359326e7 (patch)
tree95188dab2ebdd238711f6abbb5403f5d7ef83e79 /guides
parent8189abc1f23b78e4cad3857848a1333fd77eca37 (diff)
parentb217e6e7d318da6d9bfa52a6f68ca2b96bb9bd82 (diff)
downloadrails-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 'guides')
-rw-r--r--guides/source/active_record_querying.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md
index cb738f0657..270696d38d 100644
--- a/guides/source/active_record_querying.md
+++ b/guides/source/active_record_querying.md
@@ -807,6 +807,32 @@ SELECT * FROM articles WHERE id > 10 ORDER BY id DESC LIMIT 20
```
+### `reselect`
+
+The `reselect` method overrides an existing select statement. For example:
+
+```ruby
+Post.select(:title, :body).reselect(:created_at)
+```
+
+The SQL that would be executed:
+
+```sql
+SELECT `posts.created_at` FROM `posts`
+```
+
+In case the `reselect` clause is not used,
+
+```ruby
+Post.select(:title, :body)
+```
+
+the SQL executed would be:
+
+```sql
+SELECT `posts.title`, `posts.body` FROM `posts`
+```
+
### `reorder`
The `reorder` method overrides the default scope order. For example: