示例
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 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- assert put_embed rejects string-keyed external parameter maps with ArgumentError while cast_embed accepts the same external params
- assert updating an embeds_many or embeds_one collection that drops existing items raises RuntimeError unless on_replace is explicitly configured
- 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
- 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}
- assert validate_change raises Protocol.UndefinedError if the validator callback returns a boolean or tuple instead of an enumerable keyword-error list
- assert validate_change is completely bypassed when the field is unchanged in params even if present on the underlying schema struct
- 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