# \#embedded\_schema

**URL:** https://forum.elixirforum.com/tag/embedded-schema/1454.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [Using embeds\_one as a form helper and deriving persisted fields — what is the correct approach?](https://forum.elixirforum.com/t/using-embeds-one-as-a-form-helper-and-deriving-persisted-fields-what-is-the-correct-approach/74823)

<div class="topic-metadata">

**Author:** [@PaleWatcher](https://forum.elixirforum.com/u/PaleWatcher)\
**Replies:** 4\
**Last updated:** [April 2, 2026, 3:28pm UTC](https://forum.elixirforum.com/t/using-embeds-one-as-a-form-helper-and-deriving-persisted-fields-what-is-the-correct-approach/74823 "2026-04-02T15:28:09Z")

</div>

I have a schema like this: embeds\_one :product\_profile, ProductProfile, on\_replace: :delete, load\_in\_query: false I use product\_profile as a form/helper structure in LiveView (e.g. live\_select), not something I want to…

---

## [Ecto - embeds\_many as single map with unique keys](https://forum.elixirforum.com/t/ecto-embeds-many-as-single-map-with-unique-keys/65195)

<div class="topic-metadata">

**Author:** [@silverdr](https://forum.elixirforum.com/u/silverdr)\
**Replies:** 6\
**Last updated:** [October 2, 2025, 10:25am UTC](https://forum.elixirforum.com/t/ecto-embeds-many-as-single-map-with-unique-keys/65195 "2025-10-02T10:25:29Z")

</div>

I have a Parent model, which embeds\_many() children models. Children are then stored in a jsonb column as a List (Array in JSON) of simple, two-key maps (Objects), where values of one of the keys of those maps need to be…

---

## [Is there a plan to support custom loading for embedded types?](https://forum.elixirforum.com/t/is-there-a-plan-to-support-custom-loading-for-embedded-types/72548)

<div class="topic-metadata">

**Author:** [@marcandre](https://forum.elixirforum.com/u/marcandre)\
**Replies:** 3\
**Last updated:** [September 17, 2025, 9:16pm UTC](https://forum.elixirforum.com/t/is-there-a-plan-to-support-custom-loading-for-embedded-types/72548 "2025-09-17T21:16:08Z")

</div>

Custom types do not use load/dump when embedded. Then may use dump if they define embed\_as to return :dump, but there is no way to use load or any other mechanism then cast when loading data. Is there a good reason fo…

---

## [Polymorphic\_embed - polymorphic Embeds in Ecto](https://forum.elixirforum.com/t/polymorphic-embed-polymorphic-embeds-in-ecto/31951)

<div class="topic-metadata">

**Author:** [@mathieuprog](https://forum.elixirforum.com/u/mathieuprog)\
**Replies:** 16\
**Last updated:** [July 9, 2025, 12:44pm UTC](https://forum.elixirforum.com/t/polymorphic-embed-polymorphic-embeds-in-ecto/31951 "2025-07-09T12:44:02Z")

</div>

Hello :waving\_hand: I published a library that brings support for polymorphic/dynamic embeds in Ecto. Ecto’s embeds\_one macro requires a specific schema module to be specified. This library removes this restriction by …

---

## [XmlSchema - Parse and generate XML with a schema DSL](https://forum.elixirforum.com/t/xmlschema-parse-and-generate-xml-with-a-schema-dsl/59143)

<div class="topic-metadata">

**Author:** [@danj](https://forum.elixirforum.com/u/danj)\
**Replies:** 9\
**Last updated:** [November 1, 2024, 9:44pm UTC](https://forum.elixirforum.com/t/xmlschema-parse-and-generate-xml-with-a-schema-dsl/59143 "2024-11-01T21:44:37Z")

</div>

New! Parse (and generate) XML with a DSL that is built on top of Ecto.Schema. Makes handling XML easy if you want structs out of XML input. On hex: XmlSchema hexdocs: XmlSchema An example: defmodule Simple do use X…

---

## [Live View Error With Cast Embed](https://forum.elixirforum.com/t/live-view-error-with-cast-embed/62728)

<div class="topic-metadata">

**Author:** [@KP123](https://forum.elixirforum.com/u/KP123)\
**Replies:** 3\
**Last updated:** [August 26, 2024, 8:22pm UTC](https://forum.elixirforum.com/t/live-view-error-with-cast-embed/62728 "2024-08-26T20:22:46Z")

</div>

Context: I’m building an Echo schema that embeds\_one schema which itself contains an embeds\_many field. I need to allow users to add and remove from the embeds\_many field. I followed the tutorial provided in the Phoenix.…

---

## [Ecto.Changeset - How do I make validation errors in embedded schemas show up on the parent?](https://forum.elixirforum.com/t/ecto-changeset-how-do-i-make-validation-errors-in-embedded-schemas-show-up-on-the-parent/65521)

<div class="topic-metadata">

**Author:** [@bvobart](https://forum.elixirforum.com/u/bvobart)\
**Replies:** 6\
**Last updated:** [August 20, 2024, 9:53am UTC](https://forum.elixirforum.com/t/ecto-changeset-how-do-i-make-validation-errors-in-embedded-schemas-show-up-on-the-parent/65521 "2024-08-20T09:53:16Z")

</div>

Hi, I’m using Ecto embedded schemas for input validation of a JSON API. Basically, I have a Plug.Router implementation that accepts JSON and casts the input data into an Elixir struct with Ecto: ... post "/validate"…

---

## [“Module not loaded” error for PolymorphicEmbed v4.1.1](https://forum.elixirforum.com/t/module-not-loaded-error-for-polymorphicembed-v4-1-1/65294)

<div class="topic-metadata">

**Author:** [@KP123](https://forum.elixirforum.com/u/KP123)\
**Replies:** 4\
**Last updated:** [August 2, 2024, 6:00pm UTC](https://forum.elixirforum.com/t/module-not-loaded-error-for-polymorphicembed-v4-1-1/65294 "2024-08-02T18:00:12Z")

</div>

Using PolymorphicEmbed v4.1.1 I get the error: module PolymorphicEmbed.HTML.Form is not loaded and could not be found When attempting to import the module as stated in the docs Has anyone run into and fixed this probl…

---

## [\`:any\` type for embedded schemas in non-virtual fields](https://forum.elixirforum.com/t/any-type-for-embedded-schemas-in-non-virtual-fields/62812)

<div class="topic-metadata">

**Author:** [@xlive](https://forum.elixirforum.com/u/xlive)\
**Replies:** 7\
**Last updated:** [April 10, 2024, 10:01pm UTC](https://forum.elixirforum.com/t/any-type-for-embedded-schemas-in-non-virtual-fields/62812 "2024-04-10T22:01:13Z")

</div>

Hey there! We are using Ecto to parse some API response (it works pretty well!). We want this response to be converted to a struct, so we first do all the needed validations and at the end we do an apply\_action(changes…

---

## [Clearing an \`embeds\_many\` entry (\`cast\_embed/3\`)](https://forum.elixirforum.com/t/clearing-an-embeds-many-entry-cast-embed-3/62698)

<div class="topic-metadata">

**Author:** [@halostatue](https://forum.elixirforum.com/u/halostatue)\
**Replies:** 8\
**Last updated:** [April 5, 2024, 3:57pm UTC](https://forum.elixirforum.com/t/clearing-an-embeds-many-entry-cast-embed-3/62698 "2024-04-05T15:57:12Z")

</div>

If I am using cast\_embed/3, how do I clear an embeds\_many entry? I have a table flows that has a options JSONB column CREATE TABLE flows ( id bigint generated always as identity primary key, options JSONB ); I hav…

---

## [Ecto embedded\_schema storing extra/default values for fields that aren't specified](https://forum.elixirforum.com/t/ecto-embedded-schema-storing-extra-default-values-for-fields-that-arent-specified/35739)

<div class="topic-metadata">

**Author:** [@onomated](https://forum.elixirforum.com/u/onomated)\
**Replies:** 13\
**Last updated:** [February 27, 2024, 8:53pm UTC](https://forum.elixirforum.com/t/ecto-embedded-schema-storing-extra-default-values-for-fields-that-arent-specified/35739 "2024-02-27T20:53:52Z")

</div>

I’m in the process of migrating a codebase and accompanying data to Elixir/Ecto, and I notice that my embedded schema (backed by jsonb columns) now include all fields defined in the schema, even when values for those fie…

---

## [Are Ecto embedded schemas useful without a database?](https://forum.elixirforum.com/t/are-ecto-embedded-schemas-useful-without-a-database/59898)

<div class="topic-metadata">

**Author:** [@artem](https://forum.elixirforum.com/u/artem)\
**Replies:** 11\
**Last updated:** [November 22, 2023, 9:38pm UTC](https://forum.elixirforum.com/t/are-ecto-embedded-schemas-useful-without-a-database/59898 "2023-11-22T21:38:29Z")

</div>

I am still new to elixir, so once in a while getting confused with the reasoning for basic stuff Context I am building a small service that is essentially a nice looking wrapper to an external API. It is somewhat simil…

---

## [Practical use of embedded schemas for single table inheritance (STI) in Phoenix application](https://forum.elixirforum.com/t/practical-use-of-embedded-schemas-for-single-table-inheritance-sti-in-phoenix-application/57455)

<div class="topic-metadata">

**Author:** [@scoop](https://forum.elixirforum.com/u/scoop)\
**Replies:** 4\
**Last updated:** [August 7, 2023, 2:29pm UTC](https://forum.elixirforum.com/t/practical-use-of-embedded-schemas-for-single-table-inheritance-sti-in-phoenix-application/57455 "2023-08-07T14:29:33Z")

</div>

TL;DR: How do you practically use the embedded schemas when implementing single table inheritance in a Phoenix application? There are several topics on STI here and I’m pretty sure I’ve read them all, so please bare wi…

---

## [Ecto many-to-many problem caused by embedded schema](https://forum.elixirforum.com/t/ecto-many-to-many-problem-caused-by-embedded-schema/55982)

<div class="topic-metadata">

**Author:** [@chrisdel101](https://forum.elixirforum.com/u/chrisdel101)\
**Replies:** 4\
**Last updated:** [May 21, 2023, 7:09pm UTC](https://forum.elixirforum.com/t/ecto-many-to-many-problem-caused-by-embedded-schema/55982 "2023-05-21T19:09:33Z")

</div>

I’ve spent several days trying to make my this work, connecting my tables using Ecto Association Guide – Ecto v2.2.11 I think Many-to-many associations in phoenix and ecto - #5 by marick might work. But now my embedde…

---

## [Where to place embedded schemas?](https://forum.elixirforum.com/t/where-to-place-embedded-schemas/55960)

<div class="topic-metadata">

**Author:** [@defman](https://forum.elixirforum.com/u/defman)\
**Replies:** 4\
**Last updated:** [May 20, 2023, 1:35am UTC](https://forum.elixirforum.com/t/where-to-place-embedded-schemas/55960 "2023-05-20T01:35:52Z")

</div>

So I have a bunch of embedded schemas for validating incoming JSON bodies. Where would you put them in your project? I’m thinking between lib/someapp\_web/schemas/account.ex or lib/someapp\_web/controllers/account\_schema.e…

---

## [Map embed schema for changeset - take data from one structure and save it on a similar structure](https://forum.elixirforum.com/t/map-embed-schema-for-changeset-take-data-from-one-structure-and-save-it-on-a-similar-structure/54895)

<div class="topic-metadata">

**Author:** [@John\_Shelby](https://forum.elixirforum.com/u/John_Shelby)\
**Replies:** 3\
**Last updated:** [April 13, 2023, 11:26am UTC](https://forum.elixirforum.com/t/map-embed-schema-for-changeset-take-data-from-one-structure-and-save-it-on-a-similar-structure/54895 "2023-04-13T11:26:00Z")

</div>

Hello everyone, I’m trying to take data from one structure and save it on a similar structure when creating a record through function. My data is saved fine as long as I don’t send data from embed schema answers.Can so…

---

## [(Ecto.CastError) expected params to be a :map, got: \`%Hi.Msg.Translations{}\`](https://forum.elixirforum.com/t/ecto-casterror-expected-params-to-be-a-map-got-hi-msg-translations/53406)

<div class="topic-metadata">

**Author:** [@Vovchikan](https://forum.elixirforum.com/u/Vovchikan)\
**Replies:** 2\
**Last updated:** [January 25, 2023, 8:53am UTC](https://forum.elixirforum.com/t/ecto-casterror-expected-params-to-be-a-map-got-hi-msg-translations/53406 "2023-01-25T08:53:13Z")

</div>

I’m trying to use library trans. This my Schema module: defmodule Hi.Msg do use Ecto.Schema use Trans, translates: \[:msg\], default\_locale: Application.compile\_env(:hello, :locale) import Ecto.Changeset sc…

---

## [Can't save embedded schema field into database](https://forum.elixirforum.com/t/cant-save-embedded-schema-field-into-database/52345)

<div class="topic-metadata">

**Author:** [@sundevilyang](https://forum.elixirforum.com/u/sundevilyang)\
**Replies:** 4\
**Last updated:** [December 8, 2022, 8:00am UTC](https://forum.elixirforum.com/t/cant-save-embedded-schema-field-into-database/52345 "2022-12-08T08:00:36Z")

</div>

Hi, there Goal: can someone help me figure out why the field :gender can not save into database ? when I look into database, the :user\_profile field it is still the default %{}. However, the user can be registered su…

---

## [Problem trying to pipe a embedded\_schema value into a %\_\_MODULE\_\_{} struct. \*\* (ArgumentError) errors were found at the given arguments: \* 1st argument: not an atom](https://forum.elixirforum.com/t/problem-trying-to-pipe-a-embedded-schema-value-into-a-module-struct-argumenterror-errors-were-found-at-the-given-arguments-1st-argument-not-an-atom/50772)

<div class="topic-metadata">

**Author:** [@afolayan-t](https://forum.elixirforum.com/u/afolayan-t)\
**Replies:** 14\
**Last updated:** [October 7, 2022, 12:17am UTC](https://forum.elixirforum.com/t/problem-trying-to-pipe-a-embedded-schema-value-into-a-module-struct-argumenterror-errors-were-found-at-the-given-arguments-1st-argument-not-an-atom/50772 "2022-10-07T00:17:49Z")

</div>

Hi All, I’m attempting to follow this multi-step form guide When I attempt to pipe my field email into the defined struct I get the following runtime error; \[error\] pid\<0.931.0\> running CensusWeb.Endpoint (connection p…

---

## [Using custom type in embedded schema](https://forum.elixirforum.com/t/using-custom-type-in-embedded-schema/29882)

<div class="topic-metadata">

**Author:** [@krut](https://forum.elixirforum.com/u/krut)\
**Replies:** 3\
**Last updated:** [August 23, 2022, 8:54am UTC](https://forum.elixirforum.com/t/using-custom-type-in-embedded-schema/29882 "2022-08-23T08:54:22Z")

</div>

I am writing an API integration that uses embedded schemas to cast response data before it is used internally. The id fields in the responses are typically integers, and I would like them to convert them to strings. I c…

---

## [Embedded schema and JSONB](https://forum.elixirforum.com/t/embedded-schema-and-jsonb/48358)

<div class="topic-metadata">

**Author:** [@silverdr](https://forum.elixirforum.com/u/silverdr)\
**Replies:** 6\
**Last updated:** [June 14, 2022, 6:42am UTC](https://forum.elixirforum.com/t/embedded-schema-and-jsonb/48358 "2022-06-14T06:42:20Z")

</div>

This is an example from one of the very useful “FullstackPhoenix” tutorials, namely: # lib/tutorial/shop/data.ex defmodule Tutorial.Shop.Data do use Ecto.Schema import Ecto.Changeset @primary\_key false embedde…

---

## [Delete params in form when an event is triggered](https://forum.elixirforum.com/t/delete-params-in-form-when-an-event-is-triggered/47923)

<div class="topic-metadata">

**Author:** [@xlive](https://forum.elixirforum.com/u/xlive)\
**Replies:** 0\
**Last updated:** [May 23, 2022, 7:44am UTC](https://forum.elixirforum.com/t/delete-params-in-form-when-an-event-is-triggered/47923 "2022-05-23T07:44:16Z")

</div>

Hi community! I’m facing a problem with the PhoenixHTML’s form right now.. Let me give some context: We have an embedded schema Review that embeds one Topic There’s a “Create Review” form where you can search in an i…

---

## [Ecto embeds\_one\_of a few schemas](https://forum.elixirforum.com/t/ecto-embeds-one-of-a-few-schemas/45034)

<div class="topic-metadata">

**Author:** [@karang](https://forum.elixirforum.com/u/karang)\
**Replies:** 3\
**Last updated:** [January 6, 2022, 1:00am UTC](https://forum.elixirforum.com/t/ecto-embeds-one-of-a-few-schemas/45034 "2022-01-06T01:00:07Z")

</div>

Hello! I am trying to create a few different embedded schemas for storing JSON in a jsonb column in postgres using ecto. The problem is that as I have a few different schemas I am not sure how to add them to the jsonb co…

---

## [Get a map instead of a list from embeds\_many](https://forum.elixirforum.com/t/get-a-map-instead-of-a-list-from-embeds-many/43468)

<div class="topic-metadata">

**Author:** [@Sebb](https://forum.elixirforum.com/u/Sebb)\
**Replies:** 6\
**Last updated:** [November 15, 2021, 4:46pm UTC](https://forum.elixirforum.com/t/get-a-map-instead-of-a-list-from-embeds-many/43468 "2021-11-15T16:46:56Z")

</div>

I’m building an Ecto schema to cast a JSON into a struct. The data looks like this: %{ name: "Bob", ... body\_parts: \[ %{id: "head", count: 1}, %{id: "hands", count: 2}, \] } I’d like to have the body p…

---

## [How to manage embedded schema in generators and form?](https://forum.elixirforum.com/t/how-to-manage-embedded-schema-in-generators-and-form/31067)

<div class="topic-metadata">

**Author:** [@Sanjibukai](https://forum.elixirforum.com/u/Sanjibukai)\
**Replies:** 1\
**Last updated:** [July 26, 2021, 1:49pm UTC](https://forum.elixirforum.com/t/how-to-manage-embedded-schema-in-generators-and-form/31067 "2021-07-26T13:49:28Z")

</div>

Hi everybody! How do you handle embedded schemas (the map fields in JSON or JSONB) with generators and forms? I have a situation where I have one schema (Account) that will have some embedded schemas (MemberS, Contact)…

---

## [Discard invalid embed entries during casting](https://forum.elixirforum.com/t/discard-invalid-embed-entries-during-casting/39168)

<div class="topic-metadata">

**Author:** [@krut](https://forum.elixirforum.com/u/krut)\
**Replies:** 4\
**Last updated:** [April 23, 2021, 3:22am UTC](https://forum.elixirforum.com/t/discard-invalid-embed-entries-during-casting/39168 "2021-04-23T03:22:35Z")

</div>

I am wondering if there is an idiomatic way to discard invalid embed entries during casting, i.e. when Ecto.Changeset.cast\_embed/3 is called, as opposed to marking them as invalid, which will in turn make the parent chan…

---

## [Re-casting json-encoded structs gracefully](https://forum.elixirforum.com/t/re-casting-json-encoded-structs-gracefully/37271)

<div class="topic-metadata">

**Author:** [@nikokozak](https://forum.elixirforum.com/u/nikokozak)\
**Replies:** 4\
**Last updated:** [February 3, 2021, 1:44pm UTC](https://forum.elixirforum.com/t/re-casting-json-encoded-structs-gracefully/37271 "2021-02-03T13:44:42Z")

</div>

Hi all - I might have dug my own grave by going down this path, but now I’m just curious… What is the best way to re-cast data after decoding a struct that has been encoded as json in order to be persisted? I’m working w…

---

## [Adding and removing elements from jsonb field using embedded schema](https://forum.elixirforum.com/t/adding-and-removing-elements-from-jsonb-field-using-embedded-schema/37258)

<div class="topic-metadata">

**Author:** [@KiKi](https://forum.elixirforum.com/u/KiKi)\
**Replies:** 3\
**Last updated:** [February 2, 2021, 5:21pm UTC](https://forum.elixirforum.com/t/adding-and-removing-elements-from-jsonb-field-using-embedded-schema/37258 "2021-02-02T17:21:27Z")

</div>

I’m working on a small project where I’m trying to learn how to use embedded schemas. So I have albums and tracks. Album can have many tracks and they are saved in jsonb field using embedded schema. I want to be able to …

---

## [Preload associated record through embedded schema](https://forum.elixirforum.com/t/preload-associated-record-through-embedded-schema/31756)

<div class="topic-metadata">

**Author:** [@dirksierd](https://forum.elixirforum.com/u/dirksierd)\
**Replies:** 3\
**Last updated:** [December 3, 2020, 10:55am UTC](https://forum.elixirforum.com/t/preload-associated-record-through-embedded-schema/31756 "2020-12-03T10:55:52Z")

</div>

Hi there! I have a schema looking something like this: defmodule Shop.Order do schema "orders" do embeds\_many :lines, Line end end defmodule Shop.Line do embedded\_schema do belongs\_to :product, Product …

---

## [Preload associations in embeds?](https://forum.elixirforum.com/t/preload-associations-in-embeds/35021)

<div class="topic-metadata">

**Author:** [@thojanssens1](https://forum.elixirforum.com/u/thojanssens1)\
**Replies:** 5\
**Last updated:** [October 21, 2020, 9:24am UTC](https://forum.elixirforum.com/t/preload-associations-in-embeds/35021 "2020-10-21T09:24:33Z")

</div>

Say I have the following schemas: defmodule Articles do schema "articles" do field(:name, :string) embeds\_one(:foo, Foo) end def changeset(struct, attrs) do struct |\> cast(attrs, \[:name\]) |\> c…

[Next page](https://forum.elixirforum.com/tag/embedded-schema/1454.md?match_all_tags=true&page=1&tags%5B%5D=embedded_schema)
