Doctrine orm 如何在Symfony中的多对多关系的中间表中创建其他列?

Doctrine orm 如何在Symfony中的多对多关系的中间表中创建其他列?,doctrine-orm,doctrine,Doctrine Orm,Doctrine,有两个实体具有多对多关系: /** * @ORM\Entity(repositoryClass=KbFavorisRepository::class) */ class KbFavoris { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; ... /** * @v

有两个实体具有多对多关系:

/**
 * @ORM\Entity(repositoryClass=KbFavorisRepository::class)
 */
class KbFavoris
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    ...

    /**
     * @var \Doctrine\Common\Collections\Collection|KbCollection[]
     *
     * @ORM\ManyToMany(targetEntity="KbCollection", mappedBy="kb_favoris",cascade={"persist"})
     */
    protected $collection;

    ...

}

/**
 * @ORM\Entity(repositoryClass=KbCollectionRepository::class)
 */
class KbCollection
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     * @JMS\Groups({"list_collection"})
     */
    private $id;

    ...

    /**
     * @var KbFavoris
     * @ORM\ManyToMany(targetEntity="KbFavoris",inversedBy="collection", cascade={"remove"})
     * @ORM\JoinTable(
     *  name="kb_favoris_collection",
     *  joinColumns={
     *      @ORM\JoinColumn(name="collection_id", referencedColumnName="id")
     *  },
     *  inverseJoinColumns={
     *      @ORM\JoinColumn(name="favoris_id", referencedColumnName="id")
     *  }
     * )
     */
    private $kb_favoris;

    ...

}

如何在多对多关系的中间表中添加另一列?

如果要添加一些额外字段,需要创建另一个实体; 例:

新课程:

class KbFavorisKbCollection 
{
   // ManyToOne here to KbFavoris (represent one KbFavoris)
   // ManyToOne here to KbCollection (represent one KbCollection )
}

这回答了你的问题吗?
class KbFavorisKbCollection 
{
   // ManyToOne here to KbFavoris (represent one KbFavoris)
   // ManyToOne here to KbCollection (represent one KbCollection )
}