I hope you are having a nice day,
I'm using Symfony 3 and my question is:
I have 5 entities:
·Cancion ·Duracion ·Genero ·Mood ·Tempo
and I wanna have relations between them so I declared a class Cancion.php defining the relational properties with its respective annotations:
...
/*
* @ORM\ManyToMany(targetEntity="Genero", inversedBy="canciones")
* @ORM\JoinTable(name="canciones_generos",
* joinColumns={@ORM\JoinColumn(name="cancion_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="genero_id", referencedColumnName="id")}
* )
*/
private $generos;
/*
* @ORM\ManyToMany(targetEntity="Mood", inversedBy="canciones")
* @ORM\JoinTable(name="canciones_moods",
* joinColumns={@ORM\JoinColumn(name="cancion_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="mood_id", referencedColumnName="id")}
* )
*/
private $moods;
/*
* @ORM\ManyToMany(targetEntity="Tempo", inversedBy="canciones")
* @ORM\JoinTable(name="canciones_tempos",
* joinColumns={@ORM\JoinColumn(name="cancion_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="tempo_id", referencedColumnName="id")}
* )
*/
private $tempos;
/*
* @ORM\ManyToMany(targetEntity="Duracion", inversedBy="canciones")
* @ORM\JoinTable(name="canciones_duraciones",
* joinColumns={@ORM\JoinColumn(name="cancion_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="duracion_id", referencedColumnName="id")}
* )
*/
private $duracion;
public function __construct() {
$this->generos = new ArrayCollection();
$this->moods= new ArrayCollection();
$this->tempos= new ArrayCollection();
$this->duracion= new ArrayCollection();
}
and the other classes are like this (for example Duracion.php):
...
/**
* @ORM\ManyToMany(targetEntity="Cancion", mappedBy="duracion")
*/
private $canciones;
public function __construct()
{
$this->canciones = new ArrayCollection();
}
The problem is when I execute the command to update the scheme it just create 5 (corresponding to each entity) tables but not the relational tables:
php bin/console doctrine:database:drop --force;php bin/console doctrine:database:create;php bin/console doctrine:schema:update --force
In all entities I'm using:
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
What I'm doing wrong, how can I have the relational tables?
Thank you very much.