Explain Rails Active Record Query

You can output the raw query for an Active Record Query by tagging .explain at the end.

Books.where(author:"Ted").explain

EXPLAIN for: SELECT `books`.* FROM `books` WHERE `books`.`author` = 1

Very useful for complex queries where it’s hard to understand what is happening under the hood 🤯. You can read the docs for more info.

Leave a Comment