最佳答案
I want to check my understanding of cascade operations on Doctrine associations. For the purpose of this question, I have two models: Customer
and Insuree
.
If I define a many to many relationship between a Customer
and Insuree
and set cascade{"all"}
, I understand that this will:
This is the definition of the association on Customers
.
/**
* @ORM\ManyToMany(targetEntity="Insuree", inversedBy="customers", cascade={"all"})
* @ORM\JoinTable(name="customer_insuree",
* joinColumns={@ORM\JoinColumn(name="customer_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="insuree_id", referencedColumnName="id")}
* )
*/
protected $insurees;
If I define the inverse many to many relationship between an Insuree
and Customer
and set cascade{"all"}
, I understand that this will:
This is the definition of the association on Insurees
.
/**
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="insurees", cascade={"all"})
*/
protected $customers;
If I then define the relationship as to cascade on persist, merge and detach - deleting the insuree will not delete all associated customers - it will only remove the associations between the insuree and its customers?
/**
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="insurees", cascade={"persist", "merge", "detach"})
*/
protected $customers;