diff --git a/app/models.py b/app/models.py index 6ee089a..5994610 100644 --- a/app/models.py +++ b/app/models.py @@ -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):