我想知道 ActiveRecord::Base.connection.execute
方法是如何定义的。
所以我检查了源代码,但我无法理解发生了什么。
# Executes the SQL statement in the context of this connection.
def execute(sql, name = nil)
end
undef_method :execute
也许该方法是在另一个地方动态定义的。 如何找到描述该方法的地方?
最佳答案
您显示的方法在模块中定义 DatabaseStatements
这是 include
d入类AbstractAdapter
(connection_adapters/abstract_adapter.rb)。
AbstractAdapter
只是作为 Rails 与之互操作的不同数据库服务器的各种专用数据库适配器的基类;它不打算自己实例化。例如,execute
的定义PostgreSQL 数据库在 postgresql/database_statements.rb 中, 作为 class PostgreSQLAdapter < AbstractAdapter
的一部分.
关于ruby-on-rails - 如何使用 Rails 查找动态定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17360041/