const removeComments = (postId, knex) => {
  return knex('comments').where('post_id', postId).pluck('id')
  .then(ids => {
    if (ids.length === 0) return
    return knex('comments_tags').where('comment_id', 'in', ids).del()
    .then(() => knex('comments').where('id', 'in', ids).del())
  })
}

export const removePost = postId => {
  return bookshelf.transaction(trx => {
    const remove = table =>
      trx(table).where('post_id', postId).del()

    const unset = (table, col = 'post_id') =>
      trx(table).where(col, postId).update({[col]: null})

    return Promise.all([
      removeComments(postId, trx),
      remove('follows'),
      remove('user_post_relevance'),
      remove('posts_tags'),
      remove('posts_users'),
      remove('communities_posts'),
      unset('posts', 'parent_post_id')
    ])
    .then(() => trx('posts').where('id', postId).del())
  })
}

@@ -29,31 +29,20 @@
 Id, 
-kne
+tr
 x) =%3E
- %7B
 %0A  
+t
 r
-eturn kne
 x('c
@@ -142,47 +142,85 @@
 urn%0A
+%0A
     
-return knex('comments_tags'
+const remove = (table, column = 'comment_id') =%3E%0A      trx(table
 ).where(
 'com
@@ -215,28 +215,22 @@
 ).where(
-'
 co
-mment_id'
+lumn
 , 'in', 
@@ -244,77 +244,141 @@
 l()%0A
+%0A
     
-.then(() =%3E knex('comments').where('id', 'in
+return Promise.all(%5B%0A      remove('thanks'),%0A      remove('comments_Tags')%0A    %5D)%0A    .then(() =%3E remove('comments
 ', 
+'
 id
-s).del(
+'
 ))%0A  %7D)
-%0A%7D
 %0A%0Aex

remove thanks when deleting comments