V
V
vladislav9972021-10-06 14:42:46
symfony
vladislav997, 2021-10-06 14:42:46

Why is the entity that has a one-to-one relationship to itself not deleted?

Tell me why the entity in which the one-to-one relationship to itself is not deleted?

There are 2 related entities:
Course < Section

The section has this relationship in the entity:

Section.php

/**
     * @ORM\OneToOne(targetEntity=Section::class, cascade={"persist", "remove"})
     */
    private $after_send_section;


and if there is at least one value there, then the entire course or the same section is not deleted with an error:
An exception occurred while executing 'DELETE FROM section WHERE id = ?' with params [5]:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`database`.`section`, CONSTRAINT `FK_2D737AEF628DC59B` FOREIGN KEY (`after_send_section_id`) REFERENCES `section` (`id`))

How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vladislav997, 2021-10-06
@vladislav997

/**
     * @ORM\OneToOne(targetEntity=Section::class)
     * @ORM\JoinColumn(name="after_send_section", referencedColumnName="id", onDelete="CASCADE")
     */
    private $after_send_section;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question