ActiveRecord provides an easy way to select specific fields from the table using the ActiveRecord::QueryMethods#select method.

Recently ActiveRecord::QueryMethods#select added support for hash values.

Let’s see some examples with the Product and Variant models

### Before

Before 7.1, we were able to select specific fields with the following syntax:

The above results in:

### After

After ActiveRecord::QueryMethods#select added support for hash we don’t need to use the raw version of the query anymore.

Let’s take a look at the same code after this change.

The above will result in:

We can also use the following syntax that supports alias:

The above will result in: