Could not determine access type for property "file"

Please add "'mapped' => false," to form builder.

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
   ->add('file', FileType::class, 
     array(
        'data_class' => null,
        'mapped' => false,            
    ))
    ->add('name', TextType::class)
    ;
 }

Those who say that it is wrong to dissolve, see the test there. I'm not the one who made it wrong.

Test code: https://github.com/symfony/property-access/blob/master/Tests/PropertyAccessorCollectionTest.php#L151

A second solution is to add function setXxx to the property that gives an error in class Entity.

public $xxx;

public function setXxx(Array $xxx)
{
    $this->xxx = $xxx;
}

Or

public function __construct()
{
    $this->xxx = new ArrayCollection();
}

Video Link: https://knpuniversity.com/screencast/doctrine-relations/create-genus-note

My English is bad, I can tell you.


Setting mapped => false is not the real solution, because the field IS mapped to the entity.

In my case, I have a OneToMany relation, so I need the field mapped in order to use the 'cascase' => {"all"} option.

If the field is not mapped, then you must to persist the related entity manually. That's no good.

Tags:

Symfony