I have a reference table album_content which has: album_id, content_id, and sort_key. I set it up as an entity with @ManyToOne relations:
/**
* @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;
Right now Doctrine is complaining No identifier/primary key specified. What’s the correct annotation to reference these without adding an extra ID column?
First, you probably shouldn’t be naming things $contentId or $albumId, but instead just call them $content and $album.
That said, the quick solution is to add @Id annotations to both of your associations.
The manual goes into further detail about using composite keys in Doctrine 2.