Database schemas in Active Record employ certain naming conventions for the table columns depending on the purpose that the table serves.
The two main types of keys used by tables are:
If you have some column in your table named id
, then the default active record will select that column as the primary key. When you create tables with Active Record Migration,
this column is automatically added to the database table.
These are the fields in other tables that refer to the primary key of another table with which the other table is associated with. Its naming convention follows the name of the original table followed by an underscore and then id.
If the name of the table has more than more one word, it is converted into a single word name.
In order to add additional features, there are optional columns :
created_at
: When we create the first record, it automatically sets the date and time for that record.
updated_at
: When we modify or create the record, it updates the date and time.
lock_version
: Prevents the data from overriding by assuming that a database transaction conflict rarely happens. This can be done by adding an optimistic lock
.
type
: Specifies the type of model.
(association_name)_type
: Stores the type for polymorphic associations.
Free Resources