grangerelixx

grangerelixx

Ecto.Enum in Polymorphic Embed

I am trying to use Ecto.Enum in polymorphic embed. In case of normal schema, Ecto.Enum can be used as follows

@types [
    embed_comment: EmbedComment,
    serial_comment: SerialComment
  ]

  schema "posts" do

field :name, :string
field :type, Ecto.Enum, values: @types` 
timestamps()
  end

But in the below scenario, can I know what is the right syntax to use Ecto.Enum?

@types [
    embed_comment: EmbedComment,
    serial_comment: SerialComment
  ]

  schema "posts" do
    field :name, :string

    field :nodes, {:array, PolymorphicEmbed},
      types: ???

    timestamps()
  end

Any suggestions appreciated. Thank you

Most Liked

mathieuprog

mathieuprog

Just noticed your question relating to polymorphic_embed. Simply using @types should work:

field :nodes, {:array, PolymorphicEmbed}, types: @types, on_replace: :delete

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement