Skip to content

Ecto.Enum.cast_value/3#4596

Merged
josevalim merged 3 commits intoelixir-ecto:masterfrom
cjbottaro:ecto-enum-cast-value
Mar 30, 2025
Merged

Ecto.Enum.cast_value/3#4596
josevalim merged 3 commits intoelixir-ecto:masterfrom
cjbottaro:ecto-enum-cast-value

Conversation

@cjbottaro
Copy link
Copy Markdown
Contributor

@josevalim Is this what you meant by adding a function to Ecto to make this easier
phoenixframework/phoenix_html#461 (comment)

Let me know if this is what you were thinking or any changes need to be made!

@cjbottaro
Copy link
Copy Markdown
Contributor Author

Originally I was thinking to define cast_value/3 in terms of cast/2, but it felt "heavy" having to call init/1 and figuring out the options with which to call it. But maybe the "heaviness" isn't as bad as I imagine?

@cjbottaro
Copy link
Copy Markdown
Contributor Author

cjbottaro commented Mar 29, 2025

Ahh, I figured out that you can get the params via the __changeset__() function. So now cast_value/3 is defined in terms of cast/2.

Comment thread lib/ecto/enum.ex Outdated
Comment thread lib/ecto/enum.ex Outdated
Copy link
Copy Markdown
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy! Let's see if other maintainers agree too!

Co-authored-by: José Valim <jose.valim@gmail.com>
@cjbottaro
Copy link
Copy Markdown
Contributor Author

cjbottaro commented Mar 29, 2025

One really nitpicky thing... should the function be called cast_data instead of cast_value? data seems to be more inline with the terminology used throughout the file.

@josevalim
Copy link
Copy Markdown
Member

I am happy with cast_value but let's see if someone has a different opinion.

Copy link
Copy Markdown
Member

@greg-rychlewski greg-rychlewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like cast_value. It seems more inline with the other function names.

@josevalim josevalim merged commit c0f51e8 into elixir-ecto:master Mar 30, 2025
7 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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

Successfully merging this pull request may close these issues.

3 participants