Do not use the issues tracker for help or support requests (try Stack Overflow, IRC or mailing lists, etc).
empty_valuesElixir version (elixir -v): 1.3.2
In my opinion, docs aren't clear on the best way to override empty_values. After getting help on IRC, I am doing
@empty_values ["blank"]
def changeset(struct, params \\ %{}) do
struct
|> change(%{})
|> Map.put(:empty_values, @empty_values)
|> cast(params, [:foo, :bar])
end
I am still very new to Elixir and Ecto so my exposure to code is limited but this instantiating a changeset with change and then modifying the changeset's field with put all before calling cast felt a little unnatural to me.
When I first asked for help a couple people thought the changeset would read an @empty_values module attribute from my model, which ended up not being the case. After some discussion, we settled on the code above. It works but it took us a while to reach that and we weren't confident that was the best approach. It would be helpful if the docs included the recommended way to set empty values here https://hexdocs.pm/ecto/Ecto.Changeset.html#module-empty-values
I am too new to this ecosystem to have an informed opinion on API design but as a new user, I kind of expected Ecto.Changeset to provide a function that would update the empty values.
If the above code is the best way to do set new empty values, I'd be happy to open a PR updating the documentation.
Thanks for the work and time you've put into this project! I think empty values will be helpful once I figure out how to best use the feature. I love working with ecto 馃槃
Yes, we plan to provide an official API but it first requires us to deprecate the existing cast/4 API. It is coming soon, so please hang on tight. :)
Most helpful comment
Yes, we plan to provide an official API but it first requires us to deprecate the existing cast/4 API. It is coming soon, so please hang on tight. :)