Skip to content
Advertisement

How i persist data with @ManyToMany Symfony4

I have problem when I want import data (csv) officer with relation ManyToMany Department : the officer (agent in french) are store but the relation are not created (table agent_departement). Agent class :

JavaScript

Class department :

JavaScript

ImportController

JavaScript

The dump duplicate department idk why dump $agent

JavaScript

I’m a bit desperate I beat around the bush, thank you for your answers, I hope I was clear and sorry for my poor English

Advertisement

Answer

in your addDepartement function you have (and similarly named in other places …)

JavaScript

and also the containment check, and also initialization

your property name is quite different though.

JavaScript

since $this->departement is initialized in the constructor, php will happily work with it, while doctrine doesn’t notice any differences on this unmanaged property

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement