How to add a global error to an Ecto changeset? (Not specific to a single field)

In Django, there is the concept of “non_field_errors”, which exists when a form field has an error that is not specific to any model field.

I am just wondering if there is a similar convention in Ecto. I have an error that is not specific to a single field. How should I describe it? Should I just use the django naming convention for the field, e.g. :non_field_errors? For example:

Ecto.Changeset.add_error(changeset, :non_field_errors, "some reason")

Just checking for recommendations. Thanks

2 Likes

You can add those to :base.

2 Likes

Interesting, that’s also what ChatGPT suggested. Is there any precedent for this specific value?

EDIT: The venerable Dogbert suggested the value :base in a Stack Overflow answer

1 Like

I’m assuming the precedent is Rails! It also uses :base.

1 Like

Cool, works for me. I just want to have some sort of convention to work with. The fewer decisions I have to make, the better.

Thanks Brother sodapopcan!

1 Like