DEV Community

Discussion on: October 8th, 2021: What did you learn this week?

Collapse
 
djuber profile image
Daniel Uber

I learned you can add pretty specific comments about the source of SQL queries in a rails app by adding the marginalia gem to your project.

This makes it easier to tie specific queries or updates to the location in the code that called them:

  Profile Create (0.6ms)  INSERT INTO "profiles" ("created_at", "updated_at", "user_id") VALUES ($1, $2, $3) RETURNING "id" /*line:/app/models/user.rb:20:in `block (3 levels) in <class:User>'*/  [["created_at", "2021-10-13 16:56:31.006007"], ["updated_at", "2021-10-13 16:56:31.006007"], ["user_id", 218762]]
Enter fullscreen mode Exit fullscreen mode

Now, I can that this profile creation was triggered by code on line 20 in the User class definition...

Collapse
 
nickytonline profile image
Nick Taylor

Gym teacher from Glee saying amazing!