Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:45:28+00:00 2026-06-01T23:45:28+00:00

When I cascade delete one item, I want get list of all deleted items

  • 0

When I cascade delete one item, I want get list of all deleted items id (primary key) including ids of deleted children. Is it possible?

My class looks like:

class Example(Base):
    __tablename__ = 'example'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('example.id', ondelete='CASCADE'), nullable=True)
    childrens = relationship('Example', backref=backref('parent', remote_side=[id], cascade="all, delete"))

and I query like:

session.query(Example).filter(Example.id == id).delete()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:45:30+00:00Added an answer on June 1, 2026 at 11:45 pm

    The only real solution that I know of is to use triggers. There is a generalized trigger for dealing with just this type of issue which has been committed to the PostgreSQL project as an installable extension for 9.2 (expected to be released this summer). If your python environment supports the PostgreSQL LISTEN/NOTIFY feature, you could download this and use it with 9.1 or 9.0. (We [the Wisconsin court system] have had it in production use with both for months.) You would need to be able to build it from source, I’m afraid, until version 9.2 is released. If you haven’t done that before, the bottom of this page should be a good start:

    http://www.postgresql.org/docs/devel/static/contrib.html

    You can find source code for the extension here:

    http://git.postgresql.org/gitweb/?p=postgresql.git;a=tree;f=contrib/tcn;h=aa9c5813223a3996e22cabbf064d7243fa474c6c;hb=HEAD

    … and you can currently find docs here:

    http://www.postgresql.org/docs/devel/static/tcn.html

    You would need to create a trigger which executes this trigger function on each table for which you want notification. It doesn’t matter whether the DML is direct or indirect, as through the ON DELETE CASCADE clause of a foreign key definition. While the docs give an example where the function is attached to all DML, you can attach it just to DELETE if that’s what you need, like this:

    create trigger example_tcn_trigger
      after delete on example
      for each row execute procedure triggered_change_notification();
    

    Full disclosure: I wrote this for the Wisconsin court system and they allowed me to share it with the PostgreSQL community.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out why NHibernate handles one-to-many cascading (using cascade=all-delete-orphan) the way
can any one provide me full 2 mapping file which implements cascade delete. measn
I've been trying to get a delete to cascade and it just doesn't seem
I have two tables without any cascade deleting. I want to delete parent object
CREATE TABLE item ( link MEDIUMINT UNSIGNED PRIMARY KEY NOT NULL, title TEXT NOT
Is it possible to get Core Data cascade delete to delete objects more than
I have Company->Users one-to-many relationship and I would like users to be cascade deleted,
I am trying to delete a certain field from one table and I want
I'm trying to use ON CASCADE DELETE in mysql db but I can't make
How to delete a child row (on delete cascade ?) when setting a null

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.