Forum .LRN Q&A: Response to Forums and Notifications deleting threads problem in postgresql

In the forums package the notification_requests are deleted first and then the message itself.
# Remove the notifications
  notification::request::delete_all -object_id $message_id
# Remove the message
  db_exec_plsql delete_message {}
The message cannot be deleted when there is a notification referencing it. The notifications pertaining to the message need to be deleted before deletion of the message. Since we have message_id we can get a list of notifications that reference the message in the response_id and delete those notifications first. After that the message can be deleted.

One way to do this:

  • Add a query called message_notification_ids which selects the notification_id for an message_id
  • Call notification::delete to delete that notification
This can be done in notificaion::request::delete_all. delete_message would work just fine after that.

Any comments?