我有一个项目,其中我在同一个数据库上有一个 OneToMany 关系。
目前它是这样设计的:
/**
* @ORM\OneToMany(targetEntity="MyEntity", mappedBy="myCopiedItem")
*/
protected $mySource;
/**
* @ORM\ManyToOne(targetEntity="MyEntity", inversedBy="mySource")
* @ORM\JoinColumn(name="selected_myentity_copy_id", referencedColumnName="id")
*/
protected $myCopiedItem;
但是现在我必须使这种关系ManyToMany。所以我这样做了:
/**
* @ORM\ManyToMany(targetEntity="MyEntity", mappedBy="myCopiedItem")
*/
protected $mySource;
/**
* @ORM\ManyToMany(targetEntity="MyEntity", inversedBy="mySource")
* @ORM\JoinTable(name="entity_has_copy")
*/
protected $myCopiedItem;
但是symfony创建的“entity_has_copy”表只有1个项目(myentity_id),我想要2个字段“myentity_id”和“selected_myentity_copy_id”,它们都是我的“myentity”表中的实际ID......
为了在生成的表中同时拥有两个 id,我必须修改什么?
我确定我错过了一些东西,但我不知道是什么:(
注意:实体/表名已重命名以保护隐私