Ruby on rails 有没有办法检查给定的SQL是否在Rails中执行

Ruby on rails 有没有办法检查给定的SQL是否在Rails中执行,ruby-on-rails,ruby-on-rails-3,arel,active-relation,Ruby On Rails,Ruby On Rails 3,Arel,Active Relation,我想知道,有没有简单的方法来检查当前请求中是否执行了给定的SQL 假设我有 class Candy < ActiveRecord::Base def yummiest_candies @yummiest_candies = where(yummy: true, user_id: 1) end def do_something if was_executed?(yummiest_condies.to_sql) 'do something'

我想知道,有没有简单的方法来检查当前请求中是否执行了给定的SQL

假设我有

class Candy < ActiveRecord::Base

  def yummiest_candies
    @yummiest_candies = where(yummy: true, user_id: 1)
  end

  def do_something
    if was_executed?(yummiest_condies.to_sql)
      'do something'
    end
  end

  def was_executed? 
    # any ideas ??
  end
end
多谢各位

  # app/model/candy.rb
  #...
  def factory_ids
    if was_executed?(yummiest_candies.to_sql)
      yummiest_candies.collect(&:factory_id)
    else
      yummiest_candies.pluck(:factory_id)
    end
  end
  #...