所有数据库中定义的表如何使用活动记录的时候上市? [英] How to list of all the tables defined for the database when using active record?
问题描述
我如何得到所有数据库中定义的表的列表,使用活动记录时?
How do I get a list of all the tables defined for the database when using active record?
推荐答案
呼叫<一href="http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L21"><$c$c>ActiveRecord::ConnectionAdapters::SchemaStatements#tables$c$c>.这种方法是未记录在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", ...]
请参阅<一href="http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L21"><$c$c>activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21$c$c>,以及在这里的实现:
See activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21
, as well as the implementations here:
- <一个href="http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb#L412"><$c$c>activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:412$c$c>
- <一个href="http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L615"><$c$c>activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:615$c$c>
- <一个href="http://github.com/rails/rails/tree/master/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb#L176"><$c$c>activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:176$c$c>
这篇关于所有数据库中定义的表如何使用活动记录的时候上市?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!