Im new to Symfony2 (having used symfony 1.x a couple years ago) and Im trying to understand how to handle entity relationships with Doctrine2. (Incidently, it would be nice if the Symfony2 book had more relationship examples instead of simply referring to the Doctrine2 docs :-)
So I have a simple product entity that I want to relate to multiple categories (i.e. single product can be in multiple categories). On the surface this looks like a one-to-many kind of relationship right, but Im thinking a relationship like that would be done via a join table in the database. So Im doing something like this instead:
class Product
{
....
/**
* @ORM\ManyToMany(targetEntity="Category");
**/
private $categories;
}
Doing a schema update does indeed create the join table in the database as expected. But Im wondering if Im wrong in making this a many-to-many instead ? I guess Im asking about best practices and how you would do this ? Can anyone advise and/or provide examples ?