Doctrine 2 cascade={''remove"} doesn't seem to be working

前端 未结 3 1371
旧巷少年郎
旧巷少年郎 2020-12-30 04:23

Hi I have the following class

namespace MP\\User\\RegistrationBundle\\Entity;

use Doctrine\\ORM\\Mapping as ORM;
use          


        
3条回答
  •  轮回少年
    2020-12-30 04:54

    Your relationship definition seems to be fine. What is the way the customer is deleted? I mean Doctrine doesn't set "ON DELETE CASCADE" directly in database. So, if you remove customer entity in other way than "doctrine's" one, comments won't be deleted.

    You may tell doctrine to set this directly in database, by adding in annotation:

    @ORM\JoinColumn(name="icustomer_id", referencedColumnName="icustomer_id", onDelete="CASCADE")
    

    But if you're trying remove the entity in right-doctrine way ant this still doesn't work, try add "orphanRemoval" to true, it should help:

    // Customer.php
    /**
     * @var string $addresses
     * @ORM\OneToMany(targetEntity="MP\User\RegistrationBundle\Entity\Address", mappedBy="customer", cascade={"remove"}, orphanRemoval=true)
     */
    protected $addresses;
    

提交回复
热议问题