ecto-nested-associations

Installation
SKILL.md

Ecto Nested Associations

RULES — Follow these with no exceptions

  1. Use cast_assoc/3 for has_many/has_one — never manually insert children in a separate step
  2. Use Ecto.Multi for operations spanning multiple unrelated tables — do NOT use Ecto.Multi for nested associations
  3. Set on_delete explicitly in migrations:delete_all for owned children, :nothing for independent entities
  4. Always create indexes on foreign key columns
  5. Use on_replace: :delete in cast_assoc for list management — allows removing items by omitting them
  6. Preload associations before updating themcast_assoc compares against currently loaded data
  7. Do NOT require foreign keys in child changesetscast_assoc sets them automatically
  8. Use Repo.transaction/1 with Ecto.Multi — wrap multi-table operations for atomicity

End-to-End Workflow

Follow this sequence for ANY nested association or multi-table operation:

Installs
3
First Seen
3 days ago
ecto-nested-associations — igmarin/elixir-phoenix-skills