Use to_sql to see what query ActiveRecord will generate

If you’re trying to write a tricky ActiveRecord query that includes joins, complex where clauses, or selecting specific values across tables, it can be hard to remember every part of the ActiveRecord DSL.Is it joins(:orders) or joins(:order)? Should you use where(role: { name: 'Manager' }) or where(roles: { name: 'Manager' }).It’s a good idea to test these queries in the Rails console so you can quickly iterate, but sometimes you’ll be left scratching your head because when you run the code you get a weird result like:.
Use to_sql to see what query ActiveRecord will generate #ruby #rubydeveloper #rubyonrails #activerecord https://rubyonrails.ba/single/use-to_sql-to-see-what-query-activerecord-will-generate

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles