Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use with string-backed storage doesnt work #93

Open
NikitaNaumenko opened this issue Sep 16, 2019 · 1 comment
Open

use with string-backed storage doesnt work #93

NikitaNaumenko opened this issue Sep 16, 2019 · 1 comment

Comments

@NikitaNaumenko
Copy link

when i try to use EctoEnum with string-backed storage
i've got an error

== Compilation error in file lib/app/notifications/email_delivery_status_enum.ex ==
** (CompileError) lib/app/notifications/email_delivery_status_enum.ex:2: undefined function use/6
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:229: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

my enum

defmodule HexletBasics.Notifications.EmailDeliveryStatusEnum do
  use EctoEnum, "sent", "bounce", "spam", "rejected", "unsub"
end

when i used defenum, or keywords e.g, it's ok

defmodule HexletBasics.Notifications.EmailDeliveryStatusEnum do
  use EctoEnum, sent: "sent",  bounce: "bounce", spam:  "spam", rejected: "rejected", unsub:  "unsub"
end
@edisonywh
Copy link

I am having this issue too, I can verify that I am passing in strings into my changeset, but after the cast step it becomes atom.

  defenum StatusEnum, ~w(pending_payment cancelled paid refunded pending_collection fulfilled)

  def changeset(sales_order, attrs) do
    # status is string `"pending_payment"` here
    sales_order
    |> cast(attrs, [:user_id, :outlet_id, :status, :source])
    |> # status is :pending_payment here
    |> cast_assoc(:user)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants