Can't add a new ManyToMany property between entity A to B because I already have a ManyToMany property with both these entity

Viewed 50

So basically title. I'm building a music player and I would like it so that my Songs have 2 property : artists and collab-artists.

I have a Song entity which has an "artists" relational ManyToMany property where I can link 1 (or more) Artist entity to the Song. I would like to have another relational ManyToMany property "collab-artists" with Song and Artist.

I can php bin/console make:entity to create the collab-artist property but when I php bin/console make:migration I get :

In SchemaException.php line 112: The table with name 'banana.song_artist' already exists.

Seems like symfony is trying to create a table to store the relationship, but it is already used. How can I tell it to create another table with a different name ?

Thanks, Maxence

EDIT : I ended up using this solution https://stackoverflow.com/a/50344465/16267883

Which explodes the relation between 3 tables, Song > OneToMany > SongHasArtist > ManyToOne > Artist

1 Answers

You can specify the name of the join table by using the @ORM/JoinTable annotation:

/**
 * @ORM\ManyToMany(targetEntity="App\Entity\Artist", inversedBy="songs")
 * @ORM\JoinTable(name="songs_collab_artists")
 */
private $collabArtists;
Related