1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00
Files
til/rails/get-the-column-names-for-a-model.md
2019-07-16 14:01:29 -05:00

532 B

Get The Column Names For A Model

An ActiveRecord model is backed by a table in your application's database. We can get the column names for a backing table with ActiveRecords help using the .column_names method.

> Book.column_names
=> ["id", "title", "publication_year", "created_at", "updated_at", "author_id", "genre"]

Any ActiveRecord model will have access to this class method.

See the docs for more details.