Hi I have the following class
namespace MP\User\RegistrationBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\PersistentObject;
use MP\Services\SiteAdapterBundle\Util\String;
/**
* @ORM\Table(name="customer")
* @ORM\Entity(repositoryClass="MP\User\RegistrationBundle\Repositories\CustomerRepository")
* @ORM\HasLifecycleCallbacks
*/
class Customer extends PersistentObject
{
/**
* @var string $id
* @ORM\Id
* @ORM\Column(name="icustomer_id", type="integer")
*/
protected $id;
/**
* @var string $addresses
* @ORM\OneToMany(targetEntity="MP\User\RegistrationBundle\Entity\Address", mappedBy="customer", cascade={"remove"})
*/
protected $addresses;
With the following relationship
/**
* MP\User\RegistrationBundle\Entity
*/
namespace MP\User\RegistrationBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Persistence\PersistentObject;
/**
* @ORM\Table(name="custdeladd")
* @ORM\Entity(repositoryClass="MP\User\RegistrationBundle\Repositories\AddressRepository")
*/
class Address extends PersistentObject
{
/**
* @var integer $suffix
* @ORM\Column(name="isuffix", type="integer")
* @ORM\Id
*/
protected $suffix;
/**
* @var object $customer
* @ORM\ManyToOne(targetEntity="MP\User\RegistrationBundle\Entity\Customer", inversedBy="addresses", cascade={"persist"})
* @ORM\JoinColumn(name="icustomer_id", referencedColumnName="icustomer_id")
*/
protected $customer;
}
Does anybody know why when the customer gets deleted the addresses aren’t? Many thanks
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:
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: