Skip to content

Handle relation changeset error in one place#2725

Merged
josevalim merged 3 commits into
elixir-ecto:masterfrom
qcam:cam/relation-changeset-error
Oct 1, 2018
Merged

Handle relation changeset error in one place#2725
josevalim merged 3 commits into
elixir-ecto:masterfrom
qcam:cam/relation-changeset-error

Conversation

@qcam

@qcam qcam commented Oct 1, 2018

Copy link
Copy Markdown
Member

This PR intended to fix #2722, but ended up together with some slight refactoring of Ecto.Changeset.Relation module.

cast/4 and change/3 have been changed to return {:error, Ecto.Changeset.error()} instead of just :error, making error handling easier for the caller. Error messages and metadata are also encapsulated at where the data get casted/changed, making future improvements of these information, e.g based on relation type, relatively easier.

Comment thread lib/ecto/changeset.ex Outdated
{changes, errors, valid?}
:error ->
error = {key, {"is invalid", [type: expected_relation_type(relation)]}}
{:error, reason} ->

@wojtekmach wojtekmach Oct 1, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: reason is usually an atom/string/etc, in this case it's {message, metadata_kw}. It's not ideal because we're using word error a lot here, but maybe the variable should be called error still (which matches t:Ecto.Changeset.error/0 type)?

btw, thanks for this PR <3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing it out! It's fixed.

@josevalim josevalim merged commit 473222f into elixir-ecto:master Oct 1, 2018
@josevalim

Copy link
Copy Markdown
Member

❤️ 💚 💙 💛 💜

@qcam qcam deleted the cam/relation-changeset-error branch October 1, 2018 21:05
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.

Missing error metadata on invalid association

3 participants