aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fietsboek/models/track.py5
-rw-r--r--fietsboek/models/user.py15
2 files changed, 14 insertions, 6 deletions
diff --git a/fietsboek/models/track.py b/fietsboek/models/track.py
index c8b8dc5..315f484 100644
--- a/fietsboek/models/track.py
+++ b/fietsboek/models/track.py
@@ -139,12 +139,13 @@ class Track(Base):
link_secret = Column(Text)
owner = relationship('User', back_populates='tracks')
- cache = relationship('TrackCache', back_populates='track', uselist=False)
+ cache = relationship('TrackCache', back_populates='track', uselist=False,
+ cascade="all, delete-orphan")
tagged_people = relationship('User', secondary=track_people_assoc,
back_populates='tagged_tracks')
badges = relationship('Badge', secondary=track_badge_assoc, back_populates='tracks')
tags = relationship('Tag', back_populates='track', cascade="all, delete-orphan")
- comments = relationship('Comment', back_populates='track')
+ comments = relationship('Comment', back_populates='track', cascade="all, delete-orphan")
# GPX files are XML files with a lot of repeated property names. Really, it
# is quite inefficient to store a whole ton of GPS points in big XML
diff --git a/fietsboek/models/user.py b/fietsboek/models/user.py
index cc06225..75707e2 100644
--- a/fietsboek/models/user.py
+++ b/fietsboek/models/user.py
@@ -94,12 +94,19 @@ class User(Base):
is_admin = Column(Boolean, default=False)
is_verified = Column(Boolean, default=False)
- tracks = relationship('Track', back_populates='owner')
+ tracks = relationship('Track', back_populates='owner', cascade="all, delete-orphan")
tagged_tracks = relationship('Track', secondary='track_people_assoc',
back_populates='tagged_people')
- uploads = relationship('Upload', back_populates='owner')
- tokens = relationship('Token', back_populates='user')
- comments = relationship('Comment', back_populates='author')
+ uploads = relationship('Upload', back_populates='owner', cascade="all, delete-orphan")
+ tokens = relationship('Token', back_populates='user', cascade="all, delete-orphan")
+ comments = relationship('Comment', back_populates='author', cascade="all, delete-orphan")
+
+ # We don't use them, but include them to ensure our cascading works
+ friends_1 = relationship('User', secondary='friends_assoc', back_populates='friends_2',
+ foreign_keys=[friends_assoc.c.user_1_id])
+ friends_2 = relationship('User', secondary='friends_assoc', back_populates='friends_1',
+ foreign_keys=[friends_assoc.c.user_2_id])
+
@classmethod
def query_by_email(cls, email):