English 中文(简体)
Doctrine 2 One ToMany Cascade SET NUL
原标题:Doctrine 2 OneToMany Cascade SET NULL

The error

不得删除或更新母行:外国关键制约因素失败。

The classes

class Teacher {

    /**
     *@ORMOneToMany(targetEntity="publication", mappedBy="teacher")
     */
    protected $publications;
}

class Publication {

    /**
     * @ORMManyToOne(targetEntity="Teacher", inversedBy="publications")
     * @ORMJoinColumn(name="teacher_id", referencedColumnName="id")
     */
    protected $teacher;
}

I want

我想做的是,当你删除一名教师时,将教师转至全国扫盲委员会。 我想保留这一出版物,但没有提到教授。

我不知道在理论中如何能够做到这一点? 或者总是与教师的关系?

问题回答

请在贵实体的说明中添加<代码>onDelete=”SET NUL"。 出版:

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

这一修改在表态中进行了登记。 因此,您需要一个数据库迁移,或为此进行图形改动。

第6类

#[ORMJoinColumn(nullable: true, onDelete:  SET NULL )]




相关问题
Instead of NULL, should I write `0x0` or `0`?

I know that you are supposed to use 0 instead of NULL in c++ (even though NULL is defined as 0 in C++ most of the time). Recently I came across some code where 0x0 was used instead, though. What is ...

SELECT the newest record with a non null value in one column

I have table data which looks like this id | keyword | count | date 1 | ipod | 200 | 2009-08-02 2 | ipod | 250 | 2009-09-01 3 | ipod | 150 | 2009-09-04 4 | ipod | NULL | 2009-09-07 Now what I am ...

C#: Range intersection when endpoints are null (infinity)

Ok, I have these intersection methods to work with ranges, and they work well as long as the range endpoints are not null: public static bool Intersects<T>(this Range<T> first, Range<T&...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

热门标签