docs: backfill TOC + decision trees, fix review findings

- Add ## Contents and ## Decision Tree to all 10 existing pattern files
- Fix embed_as/1 semantics inversion in types.md (:self → :dump)
- Fix fabricated __meta__.changes reference in changesets.md
- Fix default primary key type (:integer → :id) in schemas.md
- Combine @impl subsections into single "Minimal Callback Annotation"
This commit is contained in:
2026-05-01 22:13:35 -07:00
parent b33accf37c
commit 10218813d3
13 changed files with 356 additions and 87 deletions
+9 -10
View File
@@ -328,17 +328,16 @@ end
**Anti-pattern:** Reimplementing the "has change?" check inside the validator:
```elixir
# BAD — redundant check; validate_change already handles this
# BAD — redundant check; validate_change already skips if :sku is unchanged
def changeset(item, params) do
item
|> cast(params, [:sku])
|> validate_change(:sku, fn :sku, value ->
if Map.has_key?(item.__meta__.changes, :sku) do
if valid_sku?(value), do: [], else: [{:sku, "invalid format"}]
else
[]
end
end)
changeset = cast(item, params, [:sku])
if Map.has_key?(changeset.changes, :sku) do
value = get_change(changeset, :sku)
if valid_sku?(value), do: changeset, else: add_error(changeset, :sku, "invalid format")
else
changeset
end
end
```