Skip to content

Commit

Permalink
chore: cascade comment removal
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 10, 2023
1 parent 6e05486 commit b2a5630
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ckanext/comments/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def thread_delete(context, data_dict):
)
if thread is None:
raise tk.ObjectNotFound("Thread not found")

context["session"].delete(thread)
context["session"].commit()
thread_dict = get_dictizer(type(thread))(thread, context)
Expand Down Expand Up @@ -242,6 +243,7 @@ def comment_delete(context, data_dict):
)
if comment is None:
raise tk.ObjectNotFound("Comment not found")

context["session"].delete(comment)
context["session"].commit()
comment_dict = get_dictizer(type(comment))(comment, context)
Expand Down
8 changes: 6 additions & 2 deletions ckanext/comments/model/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Callable, Optional, Union

from sqlalchemy import Column, DateTime, ForeignKey, Text
from sqlalchemy.orm import Query, foreign, relationship
from sqlalchemy.orm import Query, backref, foreign, relationship

import ckan.model as model
from ckan.model.types import make_uuid
Expand Down Expand Up @@ -54,7 +54,11 @@ class State:
single_parent=True,
)

reply_to: Optional[Comment] = relationship("Comment", primaryjoin=id == reply_to_id)
reply_to: Optional[Comment] = relationship(
"Comment",
primaryjoin=id == reply_to_id,
cascade="all, delete-orphan"
)

def __repr__(self):
return (
Expand Down

0 comments on commit b2a5630

Please sign in to comment.