0

In development mode, I would like to be able to see in the console where an SQL query was fired.

What is currently showing up in my console (dumb example query)

User Load (1.7ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 65 LIMIT 1

What I would like to see

application_controller.rb:68
User Load (1.7ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 65 LIMIT 1
ldavin
  • 423
  • 2
  • 5
  • 16
  • Does this answer your question? [How to get the line of code that triggers a query?](https://stackoverflow.com/questions/10911371/how-to-get-the-line-of-code-that-triggers-a-query) – Tachyons Nov 16 '21 at 01:20

2 Answers2

1

For future Googlers: The gem active_record_query_trace can also do that and more.

BrunoF
  • 3,239
  • 26
  • 39
0

checkout https://github.com/RISCfuture/sql_origin for a gem that provides that.

aabes
  • 208
  • 1
  • 12