💎 Ruby on Rails
Beginner
What are ActiveRecord associations?
Answer
ActiveRecord associations define relationships between models using macros. belongs_to — a Post belongs_to a User (posts table has user_id FK). has_many — a User has_many Posts. has_one — a User has_one Profile. has_many :through — many-to-many via a join model (User has_many Groups through Memberships). has_and_belongs_to_many (HABTM) — direct many-to-many with a join table but no join model. has_one :through — one-to-one via another model. Associations generate helper methods like user.posts, post.user, user.posts.create(...).