Doctrine2坚持两个实体oneToMany双向

时间:2014-08-20 22:12:23

标签: mysql symfony doctrine-orm

我需要坚持这个实体,但每当我试图坚持其中一个,它告诉我,我需要坚持另一个,我尝试从反面的Cascade持久性,但它没有工作。两个实体之间的关系是Session oneToMany Participant。

class Session
{
    /**
     * @ORM\ManyToMany(targetEntity="BP\QuizzBundle\Entity\Quiz" , inversedBy="sessions")
     * @ORM\JoinTable(joinColumns={@ORM\JoinColumn(name="id_session" , referencedColumnName="id_session" , nullable=false)}, 
     * inverseJoinColumns={@ORM\JoinColumn(name="id_quiz", referencedColumnName="id_quiz", nullable=false)})  
     */
    private $quizz;

    /**
     * @ORM\OneToMany(targetEntity="BP\FormationBundle\Entity\Participant" , mappedBy="session", cascade={"persist"})
     */
    private $participants;


    /**
     * @var integer
     *
     * @ORM\Column(name="id_session", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var date
     *
     * @ORM\Column(name="date_debut", type="date")
     */
    private $dateDebut;

第二个实体是:

class Participant
{
   /**
    * @ORM\Id
    * @ORM\ManyToOne(targetEntity="BP\UserBundle\Entity\Employe", inversedBy="participants")
    * @ORM\JoinColumn(name="id" , referencedColumnName="id" , nullable=false)
    */
    private $employe;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="BP\FormationBundle\Entity\Cursus", inversedBy="participants")
     * @ORM\JoinColumn(name="id_cursus" , referencedColumnName="id_cursus" , nullable=false)
     */
    private $cursus;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="BP\FormationBundle\Entity\Session", inversedBy="participants")
     * @ORM\JoinColumn(name="id_session" , referencedColumnName="id_session" , nullable=true)
     */
    private $session;

    /**
     * @var boolean
     *
     * @ORM\Column(name="is_formateur", type="boolean")
     */
    private $isFormateur;

有办法吗?

0 个答案:

没有答案