I am an active member of Ruby community. I have been consistently contributing to Ruby on Rails for a number of years and now am one of the top 30 contributors to Ruby on Rails. I also help as co-editor for the This week in Rails newsletter. Besides Ruby on Rails I have also contributed to many other notable open source projects including Sinatra, Devise and Rake. I am a seasoned speaker an have spoken at many conferences around the world including Gogaruco in San Francisco, RedDotRubyConf in Singapore, RubyConfIndia in Goa, India MadisonPlusRuby in Madison, Wisconsin, RubyConfBrazil in Suo Paulo, Brazil, and RubyConf Philippines in Manilla, Philippines. I am organizer of Deccan Ruby Conference and used to run RubyIndia Podcast. During my early days of open source as part of "Google summer of code" I contributed to the krypt-project project. Later I helped mentor in the JRuby and currently mentor in the Ruby on Rails organization for Google summer of code. When not working on Ruby, I am mostly working on Reactjs. I have authored the book Building Modern Web Applications with React.js which is published by PACKT. I have produced a number of screencasts on the topic of Learn React.js.
1 minute read
Rails 6 has addedreselect to Relation.
This allows us to change the previously added fields in select.
Rails already has rewhere
on Active Record Relation.
Using them we can override existing where or order clauses on a Relation.
Similarly if one had to select different fields per query,
one would have to do that on a new scope of the Relation.
In an existing application, we can’t always pass scope around.
We may have scopes, that already consist of the select clause.
reselect now allows us to override the existing select clause:
This is a short-hand for unscope(:select).select(fields).
Reselect unscopes the entire select statement
and replaces it with new select clause.
Changes in SQL
We can take a look at how the SQL changes with
usage of reselect: