Active Records In Ruby on Rails
Object Relation Mapping is a technique that maps the object to the database relations(tables). This helps to reduce the sql statements needed to access the database as it automatically maps the relation structure in object and the object’s data in the relation.
Convention over Configuration
Rails follow certain convention which helps to reduce configuration. It helps to save time and overhead of excessive code gets reduced. Following are some convention followed by rails.
- Naming Conventions – Rails uses some naming conventions to determine the mapping between models and database tables. Following are the naming conventions.
Model Name – Singular without underscore with first letter of each word capital. example UserArticle, People
- Schema Convention – Rails follow some conventions for schema as well. Some column names should be according to the convention based on the purpose of the column.
Foreign Keys – The syntax for a primary key is “table_name_id”, example order_id, article_id. The key point here is to note that the table name should be singular.
Primary Keys – By default “id” is used as primary key which is an auto-incremented column that gets created automatically.