How to parse a SQL string in rails. Arel object

After writing some of the large and complex SQL statements that I once asked, how could I do it better with Rails . However, in the end, I again used Arel because I couldn’t put in more conditions if I called find_by_sql.

Questions.find_by_sql(HUGE_SQL).by_filter(:popular).order('created_at').limit(5) 

My goals:

  • Sort sqls in separate files
  • Convert these string sqls to arel objects
  • The nest of this object isl with the usual reusable conditions such as "limit, order, .."

thanks

+4
source share
1 answer

The solution is to use the magic scuttle.io to convert complex SQL queries to Arel. Then you can create separate methods for each part of your request and still be able to combine them. More details in this presentation .

0
source

All Articles