vic / params

Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters.
http://hex.pm/packages/params
Apache License 2.0
364 stars 47 forks source link

don't remove empty string #28

Open exoconnor opened 6 years ago

exoconnor commented 6 years ago

This is a mildly breaking change, but is also what I assumed default behavior would be, curious what others think.

With current cast behaviour, if an empty string is sent as a param, that string gets removed, due to default empty values behaviour https://hexdocs.pm/ecto/Ecto.Changeset.html#module-empty-values

If I want to clear a text field, I typically send a json object of the form

{ field-to-clear: ""}

This is getting changed to nil, and I can't clear fields.

I could set default empty string, but there's only one update route, and other actions will send an object of form

{ other-field: 55 }

And with default empty string, this unrelated update zeroes out my text field.

This update is all that's necessary to get my narrow use case working, I haven't dug too hard into potential consequences elsewhere.

Requires ecto version bump to pass tests.

Also leaving internet as soon as I post this, so not going to be a good conversationalist for a couple days.

vic commented 6 years ago

Looks like something reasonable to me. Could you please also add a test to your PR?

I'm just not using this package right now. So I hope someone can give it a try and see if we should bump a major version or something.