W
W
wolverine7772019-05-10 16:11:16
symfony
wolverine777, 2019-05-10 16:11:16

Why won't remove() from the database work?

Hello,
please help me figure it out. I have one or more "pages" on a "book".
When I delete a book, it disappears from the database, but its pages remain.
The framework doesn't swear - but what I'm doing is definitely wrong.
Please point out the error. Thank you!

/**
   * @Route("/site/delete/{idSite}", name="delete")
   */
  public function delete(Request $request, $idSite){


        $liste_books=$this->getDoctrine()->getRepository(Book::class)->findOneBy(['idSite'=>$idSite]);


        $liste_pages=$this->getDoctrine()->getRepository(Page::class)->findBy(['idSite'=>$idSite]);
 

        $em = $this->getDoctrine()->getManager();

        $em->remove($liste_books, $liste_pages);	// так можно делать?
        $em->flush();

        return $this->redirectToRoute('site');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
user49981, 2019-05-10
@wolverine777

https://www.doctrine-project.org/projects/doctrine...
https://www.doctrine-project.org/projects/doctrine...

class Book {

    /**
     * @ORM\ManyToOne(targetEntity="Page", cascade={"remove"})
     */
    protected $pages;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question