S
S
Seintero2016-10-20 14:22:18
symfony
Seintero, 2016-10-20 14:22:18

What is the correct way to specify cascade delete?

I have two entities, Roles and Rights, with a many-to-many relationship. I want that when the Rights are deleted in the JOIN table, the rules are cleared, but the associated roles are not deleted from the Roles table ... But for some reason, either:
a) When the rights are deleted, the records in the relationship table are deleted, but the associated role is also deleted.
Here is an abstract from the rights

/**
     * @ORM\ManyToMany(targetEntity="Role", inversedBy="permissions",  cascade={"remove"})
     * @ORM\JoinTable(name="permissions_role", joinColumns={@ORM\JoinColumn(name="permissions_id", referencedColumnName="id", unique=false,onDelete="CASCADE")}, inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id", unique=false, onDelete="CASCADE")})
     */
    private $roles;

But from the roles
/**
     * @ORM\ManyToMany(targetEntity="Permissions", mappedBy="roles",  cascade={"remove"})
     */
    private $permissions;

b) If you do not specify cascade={"remove"} , then rights are removed, roles are not removed ... but related records are also not removed and errors occur due to duplicates when refilling.
Perhaps I'm missing some addition to the rules? Can anyone advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seintero, 2016-10-20
@Seintero

The question was solved, it was necessary to equate to null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question