I have multiple entities that are linked together like this
Screening (1) --> (n) Customer (1) --> (n) Matches (1) --> (n) Risk
I have added cascade={"refresh"} on every One-to-Many annotations. e.g
* @ORM\OneToMany(targetEntity="App\Entity\Risk", mappedBy="match", cascade={"persist", "remove", "detach", "refresh"})`
I need to modify the Risk entities in order to make some calculations and save the result in a Score entity, but I must reset the Risk because the changes must not be persisted in database (hence the refresh).
When I call $entityManager->refresh($screening), the modifications in Risk are persisted in database. But when I manually iterate over each relations, everything goes fine. (here is what I do in the ScreeningRepository)
foreach ($screening->getCustomers() as $customer) {
foreach ($customer->getMatches() as $match) {
foreach ($match->getRisks() as $risk) {
$this->getEntityManager()->refresh($risk);
}
$this->getEntityManager()->refresh($match);
}
$this->getEntityManager()->refresh($customer);
}
$this->getEntityManager()->refresh($screening);
Why isn't the cascade annotation working with refresh ?