---
title: "Rails 6 adds ActiveRecord::Relation#reselect"
description: "Rails 6 adds ActiveRecord::Relation#reselect method."
canonical_url: "https://www.bigbinary.com/blog/rails-6-adds-activerecord-relation-reselect"
markdown_url: "https://www.bigbinary.com/blog/rails-6-adds-activerecord-relation-reselect.md"
---

# Rails 6 adds ActiveRecord::Relation#reselect

Rails 6 adds ActiveRecord::Relation#reselect method.

- Author: Abhay Nikam
- Published: April 2, 2019
- Categories: Rails 6, Rails

Rails have
[`rewhere`](https://apidock.com/rails/ActiveRecord/QueryMethods/rewhere) and
[`reorder`](https://apidock.com/rails/ActiveRecord/QueryMethods/reorder) methods
to change the previously set conditions attributes to new attributes which are
given as an argument to method.

Before Rails 6, if you want to change the previously set `select` statement
attributes to new attributes, it was done as follows.

```ruby
>> Post.select(:title, :body).unscope(:select).select(:views)

   SELECT "posts"."views" FROM "posts" LIMIT ? ["LIMIT", 1]]
```

In Rails 6, `ActiveRecord::Relation#reselect` method is added.

The `reselect` method is similar to `rewhere` and `reorder`. `reselect` is a
short-hand for `unscope(:select).select(fields)`.

Here is how `reselect` method can be used.

```ruby
>> Post.select(:title, :body).reselect(:views)

   SELECT "posts"."views" FROM "posts" LIMIT ? ["LIMIT", 1]]
```

Check out the [pull request](https://github.com/rails/rails/pull/33611) for more
details on this.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-adds-activerecord-relation-reselect)
