Use to_sql to see what query ActiveRecord will generate
25-Mar-2021 1280
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 #to_sql #query #ActiveRecord #generate #activerecord https://www.rubyonrails.ba/link/use-to_sql-to-see-what-query-activerecord-will-generate