Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascade user deletion in related rows of tables of this module #264

Open
fenekku opened this issue Sep 2, 2021 · 0 comments
Open

Cascade user deletion in related rows of tables of this module #264

fenekku opened this issue Sep 2, 2021 · 0 comments

Comments

@fenekku
Copy link
Contributor

fenekku commented Sep 2, 2021

Is your feature request related to a problem? Please describe.

Deleting a user should cascade to the related rows in the tables defined by this module.

Currently, attempting to delete a user marks the foreignkey as null but since nullable=False, an integrity error is raised and the transaction is aborted.

Describe the solution you'd like

Add a backref cascade in appropriate places so that related rows gets deleted nicely. Example:

from sqlalchemy.orm import backref

class RemoteAccount(db.Model, Timestamp):
    # ...
    user = db.relationship(User, backref=backref('remote_accounts', cascade="all,delete"))
    """SQLAlchemy relationship to user."""

Describe alternatives you've considered

I have to delete from the bottom up i.e. figure out all models keying into User and delete those... ugh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant