Showing common and specific validation errors at the same time with Ecto

Imagine that I have some form, you have email and password fields and 2 checks: the email should be unique and the password should not contain less than 8 characters.

When I use Repo.Inserteither Repo.updateor some other method, I first receive verification errors that have nothing to do with the database (password that has less than 8 characters), and only if the password is correct will it get into the database and find that the letter is already present, and again add this to the changeset errors.

So, if a user submits a form with an existing email and a short password, he will only get an error about the latter, is there a way to always hit the database in order to get common and database specific errors at the same time?

+4
source share
1 answer

You cannot, because you can get false negatives or it can lead to other errors. For example, if an email is null, how can we check it, is it unique? In fact, your database may even be mistaken if you marked the email as NOT NULL in your database.

+2
source

Source: https://habr.com/ru/post/1605713/


All Articles