I have a problem with my symfony 5 application. When I try to insert an object with the file field set to null, I get the following error:
Caused by:
Symfony\Component\Validator\ConstraintViolation {#4637 ▼
root: Symfony\Component\Form\Form {#4042 ▶}
path: "children[file]"
value: ""
}
Symfony\Component\Form\Exception\TransformationFailedException {#4119 ▼
-invalidMessage: null
-invalidMessageParameters: []
#message: "Compound forms expect an array or NULL on submission."
#code: 0
#line: 582
trace: {▶}
}
here is the data i am sending :
WORD\BookStoreBundle\Entity\Summary {#3870 ▼
-id: 16
-title: "Contrats à durée déterminée"
-description: "bonjour ceci est une description"
-position: 0
-type: 1
-createdAt: DateTime @1673427068 {#3872 ▶}
-updatedAt: DateTime @1673427068 {#3851 ▶}
-parent: null
#file: null
-deleteAt: null
}
here is my form with file field not required :
class SummaryType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('title', Field\TextType::class)
->add('description', Field\TextType::class, array(
"required" => false
))
->add('position', Field\IntegerType::class, array(
"empty_data" => '0'
))
->add('parent', SummaryIntegerType::class, array(
"required" => false
))
->add('file', SummaryFileType::class, array(
"required" => false,
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'csrf_protection' => false,
'data_class' => 'WORD\BookStoreBundle\Entity\Summary',
'validation_groups' => array('rest_bookstore', 'rest_bookstore_summary_file'),
'file' => null
));
}
}
the file field is defined as required=false so I don't understand why I am getting this error. did i miss something?