PropelBundle icon indicating copy to clipboard operation
PropelBundle copied to clipboard

add UniqueFieldValidator

Open ienzam opened this issue 12 years ago • 5 comments

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

ienzam avatar Jun 24 '13 06:06 ienzam

There is a UniqueObject constraint for that: http://propelorm.org/cookbook/symfony2/mastering-symfony2-forms-with-propel.html#introducing-the-uniqueobject-constraint

Michael

mpiecko avatar Jun 24 '13 07:06 mpiecko

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.

ienzam avatar Jun 24 '13 08:06 ienzam

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'
    ....

mpiecko avatar Jun 24 '13 08:06 mpiecko

Ok thanks, that works :+1: I had written an validator for UniqueField, guess I don't need this anymore. Should I close this issue?

ienzam avatar Jun 24 '13 08:06 ienzam

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

mpiecko avatar Jun 24 '13 08:06 mpiecko