学说更新没有做任何事情

时间:2015-10-19 09:01:04

标签: php symfony doctrine

我尝试在两个表格上添加OneToMany双向关联:课程认证

已经有OneToMany关系但是单向。

所以我修改了两个实体以使其成为双向的,并在课程侧添加了该属性

以下是两个实体:

/**
 * Course
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="ME\ExamsBundle\Entity\CourseRepository")
 */
class Course    
{
 /**
  * @ORM\OneToMany(targetEntity="ME\ExamsBundle\Entity\Certified", mappedBy="course")
  * @ORM\JoinColumn(nullable=true)
  */
 private $certified;

//getters and setters...

}

/**
 * Certified
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="ME\ExamsBundle\Entity\CertifiedRepository")
 */
class Certified
{
/**
 * @ORM\ManyToOne(targetEntity="ME\ExamsBundle\Entity\Course", inversedBy="certified")
 * @ORM\JoinColumn(nullable=false)
 */
private $course;

// getters and setters...

}

但是当我使用命令

    doctrine:schema:update -- dump-sql

它告诉我没有什么可以更新的。

我试过

  • 清除元数据缓存

  • 删除双方可空的

  • 删除数据库并重新创建

认证属性从未出现在数据库的课程表中。

我有点被困在这里,所以任何帮助都会非常感激。

提前致谢

汤姆

1 个答案:

答案 0 :(得分:1)

Doctrine中的双向关系与SQL-point-of-view中的单向关系没有什么不同:那是因为Doctrine可以推断出从另一个表中反转外键的反向关系。在Course表中添加一个新的colum将是一个非规范化的形式,或者更糟糕的是没有任何意义。

Doctrine命令的反应是可以的。

请详细了解规范化数据库形式:https://en.wikipedia.org/wiki/Database_normalization