From 284a1384b629ca0ce967347e6758362f831c0527 Mon Sep 17 00:00:00 2001 From: skrzepto Date: Jun 10 2016 14:12:51 +0000 Subject: when a hub is deleted, delete the association and also all its widgets are deleted as well. assumption is that a widget has one parent --- diff --git a/hubs/models.py b/hubs/models.py index 742b113..1731076 100755 --- a/hubs/models.py +++ b/hubs/models.py @@ -108,7 +108,7 @@ class Association(BASE): role = sa.Column(sa.Enum(*roles), primary_key=True) user = relation("User", backref=backref('associations', cascade="all, delete-orphan")) - hub = relation("Hub", backref="associations") + hub = relation("Hub", backref=backref('associations', cascade="all, delete-orphan")) @classmethod def get(cls, session, hub, user, role): @@ -124,7 +124,8 @@ class Hub(BASE): name = sa.Column(sa.String(50), primary_key=True) summary = sa.Column(sa.String(128)) created_on = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) - widgets = relation('Widget', backref=backref('hub')) + widgets = relation('Widget', cascade='all,delete-orphan', single_parent=True, + backref=backref('hub', cascade='all')) left_width = sa.Column(sa.Integer, nullable=False, default=8) archived = sa.Column(sa.Boolean, default=False) user_hub = sa.Column(sa.Boolean, default=False)