简体   繁体   中英

doctrine remove entity with association

Hello I am working with Symfony2 and Doctrine and I can not make a thing.

I have a product entity and another entity provider:

Product * ----------- 1 provider

If I delete a provider and could leave all bone products supplier null foreign key.

result 
products provider:
    product1 (id,name,desc,id_provider=null)
    product2 (id,name,desc,id_provider=null)
    product3 (id,name,desc,id_provider=null)

I've looked cascade remove but what it does is remove products and is not what I want.

greetings and thanks.

在控制器中的删除操作中,为提供程序获取所有已加入的产品,并将其键设置为null。

您应该在JoinColumn中使用onDelete: SET NULL而不是onDelete: CASCADE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM