douxian5963 2016-05-07 12:44
浏览 21

为什么带有学说的关系表没有创建?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序
    • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入