I raise a headache about it, and I do not find a solution.
I have 2 objects: Movie.php and Category.php
I want one movie to have several categories and vice versa. This is why I chose ManyToMany relationships.
Now I'm wondering ... What is happening on the database site? Is there a "staging" table that displays movie_ids in category_ids? But that is not what happened. In fact, my first attempt was to create a MovieCategory object - I matched one movie with several categories to OneToMany, and in essence MovieCategory I made a one-way join to get the category name from my category. But I think that is not how it should work, right?
Now here is my code of how I think it should work, I really appreciate any help I can get about this:
Movie.php
<?php class Movie { public function __construct() { $this->categories = new ArrayCollection(); } protected $id; protected $moviename; protected $categories; }
category.php
<?php class Category { public function __construct() { $this->movies = new ArrayCollection(); } protected $id; protected $name;
source share