DockYard / valid_field

https://hex.pm/packages/valid_field
MIT License
48 stars 6 forks source link

[Bug fix] Param key type mismatch #8

Closed bcardarella closed 8 years ago

bcardarella commented 8 years ago

In Ecto when you are attempting to cast params that have a mix of string and atoms Ecto raises an error: https://github.com/elixir-lang/ecto/blob/master/lib/ecto/changeset.ex#L428-L429

This fix will normalize all fields in the final param map to a string. Phoenix params come in with string keys so this should be the preferred normalization direction.

danmcclain commented 8 years ago

I'd potentially argue that in the call to assert_valid_field that the user should use the string, but this takes care of them using atoms :+1:

bcardarella commented 8 years ago

Ecto allows you to use param keys as atoms, they just can't be mixed with string keys

danmcclain commented 8 years ago

You'll have the inverse of this if in your changeset you use atoms. But, like you pointed out, if you are using Phoenix, you will likely be using strings in your changeset