Doctrine symfony multiple manytomany relations in one entity - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, March 18, 2022

Doctrine symfony multiple manytomany relations in one entity

I have Email entity with 3 manyToMany.

/**
 * @ORM\ManyToMany(targetEntity=EmailGroup::class, inversedBy="emails")
 * @ORM\JoinTable(name="email_to_email_group",
 *      joinColumns={@ORM\JoinColumn(name="email_group_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="email_id", referencedColumnName="id")}
 * )
 */
private ?Collection $emailGroups;

/**
 * @ORM\ManyToMany(targetEntity=Department::class, inversedBy="emails")
 * @ORM\JoinTable(name="email_to_department",
 *      joinColumns={@ORM\JoinColumn(name="department_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="email_id", referencedColumnName="id")}
 * )
 */
private ?Collection $departments;

/**
 * @ORM\ManyToMany(targetEntity=BranchOffice::class, inversedBy="emails")
 * @ORM\JoinTable(name="email_to_branch_office",
 *      joinColumns={@ORM\JoinColumn(name="branch_office_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="email_id", referencedColumnName="id")}
 * )
 */
private ?Collection $branchOffices;

When I run php bin/console doctrine:schema:update --force I see this: enter image description here

After it in database I have 3 tables with only one foreign key, but I thought that every table should only consist of foreign keys. enter image description here

How to properly organize 3 many-to-many relationships in one entity? What am I doing wrong?



source https://stackoverflow.com/questions/71517630/doctrine-symfony-multiple-manytomany-relations-in-one-entity

No comments:

Post a Comment