Reputation: 15736
Imagine I have some form, it has email and password fields and 2 validations: email has to be unique and password should not contain less than 8 characters.
When I am using Repo.Insert
or Repo.update
or any other method like that, I first get the validation errors that have nothing to do with the database (a password that has less than 8 characters) and only if the password is correct, it will hit the database and find that the email is already present and add this to the changeset errors again.
So if the user sends a form with an already present email and a short password, he will get only the error about the latter, is there a way to always hit the database in order to get the usual and database specific errors at the same time?
Upvotes: 4
Views: 73
Reputation: 51369
You can't because you can get false negatives or it could lead to other errors. For example, if the e-mail is null, how can we validate it is unique? In fact, your database may even error if you marked the e-mail as NOT NULL in your database.
Upvotes: 2