'Symfony Doctrine Rename table used for ManyToMany

I am working on a project with symfony 5.

I need to use an existing database with existing tables. I have a problem when I create a ManyToMany relation. For example: for a ManyToMany relation for entities post and tag, doctrine create a table named post_tag.

I need to rename this table to link_post_tag. I can rename it in the sql database (easy) but what do I need to modify in symfony to make it work. Because symfony is still looking for the post_tag table.

I have looked in the doctrine and symfony documentation but found nothing.

Thanks



Solution 1:[1]

With @ORM\JoinTable. The Doctrine documentation explains it here : https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/association-mapping.html#many-to-many-unidirectional

/**
 * Many Users have Many Groups.
 * @ManyToMany(targetEntity="Group")
 * @JoinTable(name="users_groups",
 *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
 *      inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
 *      )
 */
 private $groups;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1