【问题标题】:What is the current (not yet deprecated) way to list tables in rails?在 Rails 中列出表的当前(尚未弃用)方式是什么?
【发布时间】:2018-08-20 09:49:48
【问题描述】:

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

提到了

>> ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]

它有效。虽然我很难在 Rails API 文档中找到它……但它似乎已被弃用。

看着https://apidock.com/rails/ActiveRecord/Base/connection

它说(我想是 connection() )“方法已弃用或移动”

而且它没有将 .tables 之类的东西列为方法。

它说

This method is deprecated or moved on the latest stable version. The last existing version (v3.2.13) is shown here.

These similar methods exist in v4.2.7:

ActiveRecord::ConnectionAdapters::ConnectionPool#connection
ActiveRecord::Migration#connection
ActiveRecord::ConnectionHandling#connection
ActiveRecord::Migration::CheckPending#connection

我点击了这些链接,但在任何链接上都看不到“表格”一词。

所以我看不出显示表格的非弃用方式是什么。什么是未弃用/尚未弃用的方式?

如果ActiveRecord::Base.connection.tables 未被弃用,那么我在文档中找不到它,我想知道它在哪里。

【问题讨论】:

    标签: ruby-on-rails activerecord


    【解决方案1】:

    它似乎实际上并没有被弃用,但看起来已经进行了一些重构。

    现在位于ActiveRecord::ConnectionAdapters::SchemaStatements 模块中,该模块(至少从Rails 5 开始)包含在ActiveRecord::ConnectionAdapters::AbstractAdapter 中。

    The tables method documentation 显示的内容与之前大致相同。

    【讨论】:

      猜你喜欢
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多