Symfony2, Doctrine, @UniqueEntity handle exception

后端 未结 2 2007
时光说笑
时光说笑 2021-01-23 23:40

ENTITY

use Doctrine\\ORM\\Mapping as ORM;
use Symfony\\Component\\Validator\\Constraints as Assert;
use Symfony\\Bridge\\Doctrine\\Validator\\Co         


        
2条回答
  •  太阳男子
    2021-01-24 00:14

    trouble was in form Type class, to work this unique-combination you have to add all values to fields you want to be unique, on my example will be

      $builder
                ->add('accountID', 'hidden', array ('data' => $options['acountID']))
                ->add('keyID', 'text')
                ->add('vCode', 'text');
    

    i added hidden field (accontID) and fill it with data and then i got proper error to form-errors, if you will not fill there will be null values (so i don't know why it will NOT check uniques)

    that is solution for me but basicly @Sybio help meto understand a lot of so i will check his answer as answer ^_^

提交回复
热议问题