Back to Course

Practice · Reading the Source · Card 2

Which line actually runs the SQL?

Five lines of User.where(...) chaining. Only one of them hits the database. Pick it.

The code

Reading top to bottom, which line is the moment the database wakes up?

def call
  users = User.where(active: true)            # line 1
  users = users.where(role: "admin")           # line 2
  users = users.order(:created_at).limit(10)   # line 3
  Rails.logger.info "Found admins"             # line 4
  users.each { |u| send_email(u) }             # line 5
end

The question

Which of the five lines is the first to send SQL to the database?

Take a moment. Pick the best answer. Wrong picks reveal why they're wrong, which is half the point.