I was wondering, is there easy way how to check if a given SQL was executed in current request?
let say I have
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
Obviously I can check logs, but I was wondering if there is a built in solution for this.
Also I could check if instance variable @yummiest_candies
exist but was wondering if there is solution for checking SQL
Question 2: do you think code below would be worth doing? (in much complicated scenarios maybe)
# 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
#...
Thank you