Doctrine 2: How to handle join tables with extra columns

后端 未结 2 471
梦毁少年i
梦毁少年i 2020-12-04 19:35

How do I setup a join table with extra columns, or a many-to-many association with additional properties, in Doctrine 2?

2条回答
  •  天涯浪人
    2020-12-04 20:42

    In the second article, I suggest a minor update. Instead of the full event, use a LifecycleCallback within the entity itself:

    /**
     * @ORM\Entity
     * @ORM\Table(name="jobs”)
     * @ORM\HasLifecycleCallbacks
     */
    class Job
    {
        // ...
    
        /**
         * @ORM\PreRemove
         */
        public function preRemoveCallback()
        {
            $this->setPerson(null);
            $this->setCompany(null);
        }
    }
    

提交回复
热议问题