2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails c でテーブル情報を取得するには

Last updated at Posted at 2022-03-01

テーブル情報取得
ActiveRecord::Base.connection.tables
結果
=> ["schema_migrations", "ar_internal_metadata", "contacts"]

列の名前取得
【テーブル名】.column_names
=> ["id", "name", "email", "content"]

列の情報取得
【テーブル名】.columns
結果
=>
[#<ActiveRecord::ConnectionAdapters::PostgreSQL::Column:0x0000000117e5ebc0
@collation=nil,
@comment=nil,
@default=nil,
@default_function="nextval('contacts_id_seq'::regclass)",
@name="id",
@null=false,
@serial=true,

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?