我希望你过得愉快,
我正在使用Symfony 3,我的问题是:
我有5个实体:
·Cancion ·Duracion ·的Genero ·心情 ·速度
我希望它们之间有关系,所以我宣布了一个Cancion.php类,用它各自的注释定义关系属性:
...
/*
* @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();
}
和其他类是这样的(例如Duracion.php):
...
/**
* @ORM\ManyToMany(targetEntity="Cancion", mappedBy="duracion")
*/
private $canciones;
public function __construct()
{
$this->canciones = new ArrayCollection();
}
问题是当我执行命令来更新方案时,它只创建5(对应于每个实体)表而不是关系表:
php bin/console doctrine:database:drop --force;php bin/console doctrine:database:create;php bin/console doctrine:schema:update --force
在我正在使用的所有实体中:
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
我做错了什么,我怎样才能拥有关系表?
非常感谢。