Skip to content

Instantly share code, notes, and snippets.

@michitheonlyone
Created April 29, 2025 21:30
Show Gist options
  • Save michitheonlyone/8d666c749ca6b06e9585396c1e098302 to your computer and use it in GitHub Desktop.
Save michitheonlyone/8d666c749ca6b06e9585396c1e098302 to your computer and use it in GitHub Desktop.
Symfony deactivate or disable SoftDeletableFilter if referenced entity gets deleted will get you an 500 error
// ... controller Logic use EntityManagerInterface
$filters = $entityManager->getFilters();
$filters->disable('softdeleteable');
// .. get all the needed entitys
class EntityWithNullingTheReference {
public function removeReferenceEntry(CashbookEntry $cashbookEntry): static
{
if ($this->referenceEntries->removeElement($referenceEntry)) {
// set the owning side to null (unless already changed)
if ($referenceEntry->getReference() === $this) {
$referenceEntry->setReference(null);
}
}
return $this;
}
/**
* use the following methods in you're controller to clean the references to NULL
* $project->resetAllReferenceEntries();
* $entityManager->remove($project);
* $entityManager->flush();
*/
public function resetAllReferenceEntries(): static
{
foreach ($this->referenceEntries as $referenceEntry) {
$this->removeReferenceEntry($referenceEntry);
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment