Doctrine 2 OneToMany Cascade SET NULL

You should add the option onDelete="SET NULL" in the annotation of your entity Publication like this:

class Publication
{
    /**
    * @ORM\ManyToOne(targetEntity="Teacher", inversedBy="publications")
    * @ORM\JoinColumn(name="teacher_id", referencedColumnName="id", onDelete="SET NULL")
    */
    protected $teacher;
}

This modification is registered in the table declaration itself. Hence, you need a database migration or a schema change for this to take effect.

Leave a Comment

tech