我如何得到所有数据库中定义的表的列表,使用活动记录时?
How do I get a list of all the tables defined for the database when using active record?
呼叫ActiveRecord::ConnectionAdapters::SchemaStatements#tables.这种方法是未记录在MySQL适配器,而是记录在PostgreSQL的适配器。 SQLite的/ sqlite3的也有实现的方法,但没有证件。
Call ActiveRecord::ConnectionAdapters::SchemaStatements#tables
. This method is undocumented in the MySQL adapter, but is documented in the PostgreSQL adapter. SQLite/SQLite3 also has the method implemented, but undocumented.
>> ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
请参阅activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21,以及在这里的实现:
See activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21
, as well as the implementations here: