Fix: ensure deleting a Post cascades to MapRoute, clean up relationships
This commit is contained in:
@@ -51,6 +51,7 @@ class Post(db.Model):
|
||||
gpx_files = db.relationship('GPXFile', backref='post', lazy='dynamic', cascade='all, delete-orphan')
|
||||
comments = db.relationship('Comment', backref='post', lazy='dynamic', cascade='all, delete-orphan')
|
||||
likes = db.relationship('Like', backref='post', lazy='dynamic', cascade='all, delete-orphan')
|
||||
map_route = db.relationship('MapRoute', backref='post', uselist=False, cascade='all, delete-orphan', passive_deletes=True)
|
||||
|
||||
def get_difficulty_label(self):
|
||||
labels = ['Very Easy', 'Easy', 'Moderate', 'Hard', 'Very Hard']
|
||||
@@ -213,7 +214,7 @@ class MapRoute(db.Model):
|
||||
gpx_file_id = db.Column(db.Integer, db.ForeignKey('gpx_files.id'), nullable=False)
|
||||
|
||||
# Relationships
|
||||
post = db.relationship('Post', backref=db.backref('map_route', uselist=False))
|
||||
# Relationship now defined on Post with cascade and passive_deletes
|
||||
gpx_file = db.relationship('GPXFile', backref='map_route')
|
||||
|
||||
def get_coordinates_json(self):
|
||||
|
||||
Reference in New Issue
Block a user