From 95d2bff614d02219164a2209d118ac34a3a54785 Mon Sep 17 00:00:00 2001 From: TheAMM Date: Sat, 20 May 2017 10:16:01 +0300 Subject: [PATCH] Add cascade to Torrent relationships for entry nuking (debugging purposes) Doesn't change the schema, only how SQA will handle session.delete(Torrent.by_id(1337)) --- nyaa/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nyaa/models.py b/nyaa/models.py index b7d9b6c..70fa0a7 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -89,10 +89,14 @@ class Torrent(db.Model): primaryjoin=( "and_(SubCategory.id == foreign(Torrent.sub_category_id), " "SubCategory.main_category_id == Torrent.main_category_id)")) - info = db.relationship('TorrentInfo', uselist=False, back_populates='torrent') - filelist = db.relationship('TorrentFilelist', uselist=False, back_populates='torrent') - stats = db.relationship('Statistic', uselist=False, back_populates='torrent', lazy='joined') - trackers = db.relationship('TorrentTrackers', uselist=True, lazy='joined') + info = db.relationship('TorrentInfo', uselist=False, + cascade="all, delete-orphan", back_populates='torrent') + filelist = db.relationship('TorrentFilelist', uselist=False, + cascade="all, delete-orphan", back_populates='torrent') + stats = db.relationship('Statistic', uselist=False, + cascade="all, delete-orphan", back_populates='torrent', lazy='joined') + trackers = db.relationship('TorrentTrackers', uselist=True, + cascade="all, delete-orphan", lazy='joined') def __repr__(self): return '<{0} #{1.id} \'{1.display_name}\' {1.filesize}b>'.format(type(self).__name__, self)