Add a way to unique identity a validation error #7568

Closed
alex88 opened this Issue Apr 5, 2013 · 3 comments

3 participants

@alex88

It would be nice in my opinion to be able from the validator errors to know what kind of assertion has been done to generate that error.

For example, we've inserted to the User entity an email field with value 'somebadvalue'. If we're displaying a form that's ok since it automatically shows the error in the right place and the user knows about it.

But if we manually validate the User entity, using the validation service, we've just a bunch of errors that doesn't let us know which kind of assertion has been done in an unique way.

We can just match the message but it's easy to be wrong checking only that. It would be nice to add the assertion object or at least the assertion class name, what you guys think?

@stof
Symfony member

The ConstraintViolation returned by the validator contains the propertyPath where the violation happens: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/ConstraintViolation.php#L49

Note that this is how the form error can be mapped to the right field

@alex88

It will just let you know which field has errors, not which assertion failed

@webmozart
Symfony member

Thank you for reporting this issue! This seems to be a duplicate of #7273.

@webmozart webmozart closed this Feb 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment