In my Symdony2 project I've two related entities: Service and ServiceGroup. This should be many-to-many relationship, because each group can have many services, and each service can belongs to many groups. Moreover, I need a user interface to manage services and groups. So, when editing a Service, user should be able to choose to which groups it belongs. Analogously, when editing a ServiceGroup user should be able to choose which services belongs to this group. I've already achieved this by setting up a Many-To-Many relation in my Doctrine entites. Everything is working like a charm, including user interface build on custom form types in Symfony2 (I've used "entity" form field type to allow user to select services in ServiceGroup editor and groups in Service editor). The only problem I've is that I cannot use Doctrine command line to update database schema anymore.
Here is part of my Service entity source code:
class Service
{
/**
* @var ArrayCollection $groups
* @ORM\ManyToMany(targetEntity="ServiceGroup")
* @ORM\JoinTable(
* name="service_servicegroup",
* joinColumns={@ORM\JoinColumn(name="service_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="servicegroup_id", referencedColumnName="id")}
* )
*/
private $groups;
}
And here is part of my ServiceGroup entity source code:
class ServiceGroup
{
/**
* @var ArrayCollection $services
* @ORM\ManyToMany(targetEntity="Service")
* @ORM\JoinTable(
* name="service_servicegroup",
* joinColumns={@ORM\JoinColumn(name="servicegroup_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="service_id", referencedColumnName="id")}
* )
*/
private $services;
}
I