CodeSampleX

サンプル

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

検証済みサンプル — hex ecto 3.14.1: Manage embedded schemas with cast_embed and put_embed, handle on_replace lifecycle traps, and navigate changeset field, validator…

sha256:ae752db5d7927ae9032a038840a9dc4c05edb909194c15efd4a16dd03309aff5

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
2
宣言された環境 elixir 1 linux x64 elixir 1 elixir mix

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
Manage embedded schemas with cast_embed and put_embed, handle on_replace lifecycle traps, and navigate changeset field, validator, and constraint contracts
パッケージ
シンボル
  • 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
環境
elixir 1
作成日
2026-08-17T04:42:59Z

コントラクト

  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

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

オリジンシーダー

csx-seed