Queries in rails will at some point call the select_all(arel, name = nil, binds = [])
method as defined here:
https://github.com/rails/rails/blob/89a7187cc0d893da67f53d3215a33043905d68ed/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb#L22
You can see that this method will handle the query to the select(sql, name = nil, binds = [])
method. Furthermore, this method handles the query to his parent method because of the use of undef_method :select which you can se in it's definition:
https://github.com/rails/rails/blob/89a7187cc0d893da67f53d3215a33043905d68ed/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb#L354
Finally, this means that the select method that is executed is the ConnectionAdapter method, for example the posgresql adapter, as you can see in line 946 of:
https://github.com/rails/rails/blob/89a7187cc0d893da67f53d3215a33043905d68ed/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
So, first option:
-You could edit one of those files to include some information that they were called, in a log for example.
Second, I don't know if it would work:
- You could rewrite the select_all(arel, name = nil, binds = [])
to raise an exception like:
def select_all(arel, name = nil, binds = [])
raise "error"
end
and when you want to cancel this overwrite you would undef your method with:
undef_method :select_all
So you would pass the select_all to the parent.
But Again, I don't know if the second works, but the first certainly works, although it's very invasive to edit rails core to include a log functionality.