CodeSampleX

Sample

ecto 3.14.1: Manage embedded schemas with cast_embed and put_embed, handle on_replace lifecycle traps, and navigate changeset field, validator, and constraint contracts

Verified sample for hex ecto 3.14.1: Manage embedded schemas with cast_embed and put_embed, handle on_replace lifecycle traps, and navigate changeset field…

sha256:ae752db5d7927ae9032a038840a9dc4c05edb909194c15efd4a16dd03309aff5

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment elixir 1 linux x64 elixir 1 elixir mix

Verification-run environments

Environment Contract Stages Run
elixir 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-17
elixir 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · hex@1
2026-08-18

Case

HOW
Goal
Manage embedded schemas with cast_embed and put_embed, handle on_replace lifecycle traps, and navigate changeset field, validator, and constraint contracts
Packages
Symbols
  • Ecto.Changeset.put_embed
  • Ecto.Changeset.cast_embed
  • Ecto.Schema.embeds_one
  • Ecto.Schema.embeds_many
  • Ecto.Changeset.fetch_field
  • Ecto.Changeset.fetch_change
  • Ecto.Changeset.validate_change
  • Ecto.Changeset.unique_constraint
Environment
elixir 1
Created
2026-08-17T04:42:59Z

Contract

  1. assert put_embed rejects string-keyed external parameter maps with ArgumentError while cast_embed accepts the same external params
  2. assert updating an embeds_many or embeds_one collection that drops existing items raises RuntimeError unless on_replace is explicitly configured
  3. assert cast_embed on an embeds_many collection matches params by primary key id to update existing items, creates new items for params lacking id, and marks omitted items for deletion when on_replace is :delete
  4. assert fetch_field returns {:changes, value} for changed fields and {:data, value} for unchanged schema fields instead of standard {:ok, value} tuples, while fetch_change returns {:ok, value}
  5. assert validate_change raises Protocol.UndefinedError if the validator callback returns a boolean or tuple instead of an enumerable keyword-error list
  6. assert validate_change is completely bypassed when the field is unchanged in params even if present on the underlying schema struct
  7. assert unique_constraint and foreign_key_constraint only record metadata on a source-backed changeset and leave valid? true with empty errors

Files

  • NOTES.md
  • csx.json
  • lib/ecto_embeds.ex
  • mix.exs
  • mix.lock
  • test/contract_test.exs
  • test/test_helper.exs

Download the source artifact (tar.gz)

Origin Seeder

csx-seed