active-record-associations

Installation
SKILL.md

Active Record Associations Expert

Define correct, performant, and maintainable associations between Rails models.

Philosophy

Core Principles:

  1. The FK lives on the belongs_to side — always. If you're confused about where it goes, ask "which table has the _id column?" That model gets belongs_to.
  2. Always set dependent: — orphaned records are bugs waiting to happen.
  3. Prefer has_many :through over has_and_belongs_to_many — every time. HABTM is a dead end you'll regret.
  4. Bi-directional by default — declare both sides. Use inverse_of when Rails can't infer it.
  5. Eager load aggressively — N+1 queries are the #1 performance killer in Rails apps.
  6. Database constraints back up model associations — foreign keys, indexes, and unique constraints belong in migrations, not just models.

When To Use This Skill

  • Defining relationships between models (one-to-one, one-to-many, many-to-many)
  • Creating migrations with foreign keys and join tables
  • Fixing N+1 query problems
Related skills

More from thinkoodle/rails-skills

Installs
4
GitHub Stars
4
First Seen
12 days ago