-1

i need to disallow delete function in an entity if is linked to another

for example there are two entity Product and Category, and Category is linked to Product with a relationship oneToMany or ManytoMany

i want disallow the delete function of an element in Category if this element is linked in a product element

is possible?

thank you

1 Answers1

0

You can check if the ArrayCollection contains more than 0 entities. If that is the case block deletion of the entity by using some sort of validation. Since you didn't specify wether you're submitting an admin, form or block. I will assume this is for an admin class.

There is an chapter about validation within admin classes in the Sonata Documentation. Within the validate(ErrorElement $errorElement, $object) you can check $object for the collection and amount of entities in the colleciton.

Neodork
  • 126
  • 1
  • 6