Skip to content

Commit 2c196e0

Browse files
committed
bug #451 Delete all post/tag entries on delete a Post (yceruto, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Delete all post/tag entries on delete a Post We can't use cascade delete constraint in this case because Foreign key support is not enabled in SQLite by default. (https://www.sqlite.org/foreignkeys.html#fk_enable) More information about it: - doctrine/dbal#2104 - doctrine/dbal#1204 So my only one solution was to clear this relations manually. Commits ------- 644d792 Updated the help note 6e1396e Delete all post/tag entries on delete Post
2 parents 2136e68 + 644d792 commit 2c196e0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/AppBundle/Controller/Admin/BlogController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public function deleteAction(Request $request, Post $post)
177177

178178
$entityManager = $this->getDoctrine()->getManager();
179179

180+
// Delete the tags associated with this blog post. This is done automatically
181+
// by Doctrine, except for SQLite (the database used in this application)
182+
// because foreign key support is not enabled by default in SQLite
183+
$post->getTags()->clear();
184+
180185
$entityManager->remove($post);
181186
$entityManager->flush();
182187

0 commit comments

Comments
 (0)