validation - Replace object for null in form symfony2 -
validation - Replace object for null in form symfony2 -
i have similar problem this: replace object null value using form builder in symfony2
i have entity called classification has manytoone relationship entity called typeclassification (one classification belong 1 type classification, or none typeclassfication).
classification.php:
/** * @orm\manytoone(targetentity="typeclassification", inversedby="classifications", fetch="eager") */ private $typeclassification;
typeclassification.php:
/** * @orm\onetomany(targetentity="classification", mappedby="typeclassification") */ private $classifications;
the form classification generated default symfony works, here code:
public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('name') ->add('namejapanese') ->add('ldapid') ->add('typeclassification','entity', array('class' => 'acmemybundle:typeclassification','required' => false)); }
my problem relies in entity selection field. allow null value, , set relationship null.
as said works far, add together validation constraints entity classification, if not related relationship @ all:
validation.yml:
acme\mybundle\entity\classification: #if commend constraints, works properly. constraints: - symfony\bridge\doctrine\validator\constraints\uniqueentity: { fields: name, message: unique.name } - symfony\bridge\doctrine\validator\constraints\uniqueentity: { fields: ldapid, message: unique.ldapid } #for properties doesn't matter if here or not properties: name: - notblank: message: not.blank namejapanese: - notblank: message: not.blank ldapid: - notblank: message: not.blank
then unable set relationship null. if comment constraints part, can set null.
why happen? , how can create have both validation , ability set relationship null?
that's because uniqueentity constraint validator, treats null's duplicates. create own validator service , checks there.
forms validation symfony2 doctrine2 symfony-2.3
Comments
Post a Comment