I'm working on this interface using Symfony2, here I've blogs and categories associated to them, sometimes we want to remove Blogs that are not longer valid, so I want to remove just the blog, I added this function to the controller, it does removes the Blog, but at the same time it removes all of the associated categories:
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$blawg = $em->getRepository('BlogBundle:Blog')->find($id);
if (!$blog) {
throw $this->createNotFoundException('Unable to find Blog entity.');
}
$em->remove($blog);
$em->flush();
}
return $this->redirect($this->generateUrl('blogs_inactive'));
}
What can I do to just remove the Blog information? Inside the DB I've the following tables (Entities on Synfony2): Blog, Feed, Categories, Blog Posts.
Blog Entity:
/**
* @var Category[]
*
* @ORM\ManyToMany(targetEntity="Category", cascade={"all"})
* @ORM\JoinTable(name="blog_categories",
* joinColumns={@ORM\JoinColumn(name="blog_id", referencedColumnName="blog_id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="category_id")}
* )
*/
private $categories;
/**
* @var Feed
* @ORM\OneToOne(targetEntity="Feed", mappedBy="blog", cascade={"all"})
*/
private $feed;
/**
* @var ArrayCollection $posts
* @ORM\OneToMany(targetEntity="BlogPost", mappedBy="blog")
*/
private $posts;
Feed Entity:
/**
* @var Blawg
*
* @ORM\ManyToOne(targetEntity="Blog")
* @ORM\JoinColumn(name="blog_id", referencedColumnName="blog_id",
* onDelete="CASCADE")
*/
private $blawg;