【问题标题】:Doctrine 2.1 reference table教义2.1参考表
【发布时间】:2011-12-26 23:03:15
【问题描述】:

我有一个参考表album_content,它有:album_idcontent_idsort_key。我将其设置为具有@ManyToOne 关系的实体:

/**
 * @ManyToOne(targetEntity="Album")
 * @JoinColumns({
 *  @JoinColumn(name="album_id", referencedColumnName="id")
 * })
 */
private $albumId;

/**
* @ManyToOne(targetEntity="Content")
* @JoinColumns({
*  @JoinColumn(name="content_id", referencedColumnName="id")
* })
*/
private $contentId;

/**
* @Column(name="sort_key", type="integer", nullable=false)
*/
private $sortKey;

现在 Doctrine 正在抱怨 No identifier/primary key specified。在不添加额外 ID 列的情况下引用这些的正确注释是什么?

【问题讨论】:

    标签: php annotations doctrine-orm relational-database


    【解决方案1】:

    首先,您可能不应该将事物命名为 $contentId 或 $albumId,而应将它们命名为 $content 和 $album。

    也就是说,快速的解决方案是将@Id 注释添加到您的两个关联中。

    该手册更详细地介绍了使用composite keys in Doctrine 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 2012-09-30
      • 1970-01-01
      • 2016-01-29
      • 1970-01-01
      相关资源
      最近更新 更多