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

Enum array can contain null values or an empty array #107

Open
Sgoettschkes opened this issue May 7, 2020 · 0 comments
Open

Enum array can contain null values or an empty array #107

Sgoettschkes opened this issue May 7, 2020 · 0 comments

Comments

@Sgoettschkes
Copy link

I've encountered the following behaviour which I suggest should either be pointed out in the docs or fixed in the code.

Using an EctoEnum within an array of values, the array can be empty or can contain nil values.

Have an EctoEnum:

EctoEnum.defenum(
  TestApp.MyEnum,
  :my_enum_type,
  [:one, :two, :three]
)

Have a field defining an array of EctoEnum:

field(:my_enum, {:array, TestApp.MyEnum}, default: [:one])

Define the migration for the field:

add(:my_enum, {:array, :my_enum_type}, null: false)

With this code, I can set the field to [:one], [:two, :three], which is correct and the expected behaviour. Setting the field to [:four] or [:one, :four] results in an invalid changeset, which is expected as well. Setting the field to [], [nil] or [:one, nil] results in a valid changeset which I didn't expect to happen. I would expect this values to result in an invalid changeset as well.

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

1 participant