php - Symfony2 form don't persist empty collection -


i have form containing entity collection :

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('name', 'text')         ->add('fichiers', 'collection', array(             'type' => new fichiertype(),             'allow_add' => true,             'allow_delete' => true,             'by_reference' => false         ))     ; } 

but, collection contains 4 non required field :

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('url', 'text', array(             'required' => false         ))         ->add('name', 'text', array(             'required' => false         ))         ->add('size', 'text', array(             'required' => false         ))         ->add('type', 'text', array(             'required' => false         ))     ; } 

but if validate form, don't want insert collection because fields null :

an exception occurred while executing 'insert fichier (url, name, size, type, groupe_id) values (?, ?, ?, ?, ?)' params [null, null, null, null, 2]:

in fichier entity file, sure have nullable=true annotation

like:

/**  * @var string  *  * @orm\column(name="foo", type="string", nullable=true)  */ private $foo; 

and yaml mapping:

  foo:       type: string       column: foo       nullable: true 

otherwise generated db-scheme default nullable=false, insert exception


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -