Import values over seeds.exs

Hi
I want to import some values for testing. But I use a Enum in my table. The Enum is pretty smple. It is defined in the schema file, like @val_type ~w[a, b, c]a

The input over the web is running. But I want to import in one Table. Over the seeds.exs there are values to fill my table. But how I can import a Enum value. I tried with a lot of strings.

“a” does not work
[a] does not work

Can you plesase help?

When using the sigil w or W, they’re space separated, and you don’t need to include any other delimiters like commas, so that syntax would actually produce the equivalent of ["a,", "b,", "c"]. I’d wager it’s not what you wanted. If you correct for that by removing your commas, do you still have any remaining issues?

https://hexdocs.pm/elixir/Kernel.html#sigil_w/2

You may also be looking for this for a different step in your goal:

https://hexdocs.pm/ecto/Ecto.Enum.html#values/2

2 Likes

Hi shanesveller
Your Idea solved my question. My code can not be modified because I need an Enum with Atom inside.

But if i use :a instead of “a” it works! Great

No, that’s not the reason. But cool that you made it work.

Ok, not a reason. But what is the alternative?

Show us how you made it work? It seemed like you ignored @shanesveller’s advice about the ~w sigil to me.