add UniqueFieldValidator
UniqueFieldValidtor can check a field for uniqueness, so that we can do
Some\DemoBundle\Model\User:
properties:
username:
- Propel\PropelBundle\Validator\Constraints\UniqueField:
message: some.custom.message
There is a UniqueObject constraint for that: http://propelorm.org/cookbook/symfony2/mastering-symfony2-forms-with-propel.html#introducing-the-uniqueobject-constraint
Michael
Yes, but the documentation lacks how to bind it to a specific field, the constraint is bound to the whole object. Is there any way to bind it to a field?
Also is there is any way to write constraint to the property like other constraints? That will be easy to understand.
Yes you're right. You can use it only on the whole class. But this is usefull if you're validating more than one field to be unique. If you want to display an error message beside the "username" field you can use the "errorPath" option:
....
'errorPath' => 'username'
....
Ok thanks, that works :+1: I had written an validator for UniqueField, guess I don't need this anymore. Should I close this issue?
I think you should leave it to the core devs. Maybe this coud be a feature for an upcoming release to bind this constraint to a field directly. :)
Michael