Мне хотелось бы понять, действительно ли это необходимо и почему.
Контекст
У меня есть сущность Досье с отношением OneToMany к Echeance:
Код: Выделить всё
#[ORM\OneToMany(mappedBy: 'dossier', targetEntity: Echeance::class, orphanRemoval: true)]
private Collection $echeances;
Код без toArray()
Код: Выделить всё
foreach ($dossier->getEcheances() as $echeance) {
if (!$this->hasActiveReglement($echeance)) {
$dossier->removeEcheance($echeance);
}
}
Альтернативная версия с toArray()
Код: Выделить всё
foreach ($dossier->getEcheances()->toArray() as $echeance) {
if (!$this->hasActiveReglement($echeance)) {
$dossier->removeEcheance($echeance);
}
}
- Действительно ли небезопасно удалять элементы из коллекции Doctrine во время итерации по ней?
Подробнее здесь: https://stackoverflow.com/questions/798 ... ng-over-it
Мобильная версия