Search code examples
mysqlsymfonymany-to-manyone-to-many

Many to many and Many to One relation in Symfony


I have a scenario where many persons belong to many business and many persons belong to many sub business

Also 1 business may have many sub business

I am done with the part where 1 business belongs to many sub business

For the Persons entity where we have 2 many to many business I am looking for a join table with following structure

Join Table name: person_business

Join Table Fields : person_id,business_id,subbusiness_id

What I am doing is

 /**
     * Business
     *
     * @ORM\ManyToMany(targetEntity = "buslvlone", inversedBy = "id")
     * @ORM\JoinTable(name = "person_business")
     */
    private $businesses;

    /**
     * Sub Business
     *
     * @ORM\ManyToMany(targetEntity = "buslvltwo", inversedBy = "id")
     * @ORM\JoinTable(name = "person_business")
     */
    private $subbusiness;

But when I run to update schema from console I get Error "The table with name 'advocacy_business' already exists."


Solution

  • You have two entities using the same annotation :

    /** @ORM\Table(name="advocacy_business") */