Defining Your Data

Learn to define your own data using Active Record

In Depot, we defined a number of models, including one for an Order. This particular model has a number of attributes, including an email address of type String. In addition to the attributes that we defined, Rails provides an attribute named id that contains the primary key for the record. Rails also provides several additional attributes, including attributes that track when each row was last updated. Finally, Rails supports relationships between models, like the relationship between orders and line items.

When you think about it, Rails provides a lot of support for models. Let’s examine each in turn.

Organizing using tables and columns

Each subclass of ApplicationRecord wraps a separate database table. By default, Active Record assumes that the name of the table associated with a given class is the plural form of the name of that class. If the class name contains multiple capitalized words, the table name is assumed to have underscores between these words.

Get hands-on with 1400+ tech skills courses.