How to list of all the tables defined for the database when using active record?

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", ...]

See activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:21, as well as the implementations here:

Leave a Comment