From 157572d9cacc022d7d72f7f3914725dcb19e8f6a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 30 Oct 2013 17:06:35 +0100 Subject: [PATCH] Fixed post deletion When post was deleted foreign keys in corresponding comments weren't NULLified. --- src/Controllers/PostController.php | 5 +++++ src/Models/Model_Comment_QueryBuilder.php | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 3f1ec428..c9cd91da 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -457,6 +457,11 @@ class PostController if (InputHelper::get('submit')) { //remove stuff from auxiliary tables + foreach ($post->ownComment as $comment) + { + $comment->post = null; + R::store($comment); + } $post->ownFavoritee = []; $post->sharedTag = []; R::store($post); diff --git a/src/Models/Model_Comment_QueryBuilder.php b/src/Models/Model_Comment_QueryBuilder.php index 59015c75..e94a9b66 100644 --- a/src/Models/Model_Comment_QueryBuilder.php +++ b/src/Models/Model_Comment_QueryBuilder.php @@ -3,7 +3,11 @@ class Model_Comment_QueryBuilder implements AbstractQueryBuilder { public static function build($dbQuery, $query) { - $dbQuery->from('comment'); - $dbQuery->orderBy('id')->desc(); + $dbQuery + ->from('comment') + ->where('post_id') + ->is()->not('NULL') + ->orderBy('id') + ->desc(); } }