Tell me who works with doctrine, as in my case correctly add entries.
There is a table Category -> id , name it is filled with categories.
// film.php /** * @ORM\ManyToMany(targetEntity="Category") * @ORM\JoinTable(name="films_categories", * joinColumns={@ORM\JoinColumn(name="film_id", referencedColumnName = "id")}, * inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}) */ private $categories; public function __construct(){ $this->categories = new ArrayCollection(); } public function addCategories(ArrayCollection $categories){ dump($categories); die; foreach($categories as $category){ $this->categories->add($category); } } I have an array with data:
// Π² ΡΠΈΠΊΠ»Π΅ Π·Π°ΠΏΠΎΠ»Π½ΡΡ ΡΡΡΠ½ΠΎΡΡΡ ΡΠΈΠ»ΡΠΌ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠ΅ΠΉ. foreach($data as $key => $info) { $film = new Film(); $film->SetTitle($info['title']); // ΠΌΠ°ΡΡΠΈΠ² Ρ ΠΊΠ»ΡΡΠ°ΠΌΠΈ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΉ $info['genres'] = ['array key' => 'category key'] The categories were initially entered into the Database in the Category table, about 20 of them, the table with films is empty. I have an array of data about each film, as well as what categories it belongs to. How to fill in the movie with information is understandable. But how to add a link to the categories? Sketches of code that counted something to tell you, threw off. Write if you need any other information.
I get
Type error: Argument 1 passed to AppBundle \ Entity \ Film :: addCategories () must be an instance of Doctrine \ Common \ Collections \ ArrayCollection, instance o