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

field_value/3 conversion behaviour seems inconsistent #83

Closed
schnittchen opened this issue May 30, 2017 · 2 comments
Closed

field_value/3 conversion behaviour seems inconsistent #83

schnittchen opened this issue May 30, 2017 · 2 comments

Comments

@schnittchen
Copy link

Hello,

I have an Ecto schema with a Money.Ecto.Type field and noticed the following:

When rendering a changeset from the schema without errors, field_value returns a Money struct.
In the presence of an error (on another field), it returns the value represented as a string like "0.80".
This broke a custom field render function of mine.

Note that the behaviour has been changed by upgrading ecto (!) from ref "52b354" to 2.1.4. Previously, field_value would always return Money structs.

The new behaviour is possibly desired, if so I would like to understand why.

@josevalim
Copy link
Member

Are you sure only the Ecto version changed?

In any case, this behaviour is desired because in case of errors, you want to show what the user typed, and what the user typed may not be a valid type/struct, exactly in case of errors, so you need to be able to handle raw values in your input.

@schnittchen
Copy link
Author

Yes, only ecto changed.

Thank you for clarifying! Hopefully others confused in the same way find this.

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

2 participants