Fixed post deletion

When post was deleted foreign keys in corresponding comments weren't NULLified.
This commit is contained in:
Marcin Kurczewski 2013-10-30 17:06:35 +01:00
parent 19eea1e5b6
commit 157572d9ca
2 changed files with 11 additions and 2 deletions

View file

@ -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);

View file

@ -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();
}
}