Active Record Basics
ORM fundamentals.
What Is Active Record?
Active Record is the ORM (Object-Relational Mapper) layer of Rails. It connects Ruby objects to rows in a database table so you work with objects instead of raw SQL.
- A class maps to a table.
- An instance maps to a row.
- An attribute maps to a column.
Defining a Model
A model is a class that inherits from ApplicationRecord (which inherits from ActiveRecord::Base). By convention a User model maps to the users table automatically.
class User < ApplicationRecord
end
# Maps to the 'users' table
# Columns become attributes automaticallyAll lessons in this course
- Active Record Basics
- Migrations
- Associations
- Validations and Queries