Vasya Petrov
Vasya Petrov

Reputation: 145

Doctrine unexpected behavior on bidirectional relations

I define two entities with bidirectional relations:

One

\App\Entity\Product:
...
  manyToOne:
    productSet:
      targetEntity: App\Entity\ProductSet
      inversedBy: products
      cascade: ["all"]
      joinColumn:
        onDelete: RESTRICT
...

And two

\App\Entity\ProductSet:
...
  oneToMany:
    products:
      targetEntity: App\Entity\Product
      mappedBy: productSet
      cascade: ['all']
...

If I drop all related Product entities, the related productSet entity automatically dropped too. And I don't understand why. How I prevent this behavior?

Doctrine version 2.6.3

Upvotes: 0

Views: 24

Answers (1)

myxaxa
myxaxa

Reputation: 1381

according to docs - https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/working-with-associations.html#transitive-persistence-cascade-operations

and you have cascade: ['all'] - the behavior is as expected

Upvotes: 1

Related Questions