diff --git a/app/models/game_player.py b/app/models/game_player.py index ae5cda0..864f6c4 100644 --- a/app/models/game_player.py +++ b/app/models/game_player.py @@ -1,5 +1,7 @@ +from sqlalchemy.ext.associationproxy import association_proxy + from app import db -from app.models import Role +from app.models import Role, NotificationPlayer class GamePlayer(db.Model): __tablename__ = 'game_player' @@ -9,3 +11,10 @@ class GamePlayer(db.Model): role = db.Column(db.Enum(Role), server_default=Role(0).name, nullable=False) game = db.relationship('Game', back_populates='game_players') user = db.relationship('User', back_populates='user_games') + + player_notifications = db.relationship( + 'NotificationPlayer', + back_populates='recipient', + cascade='save-update, merge, delete, delete-orphan') + notifications = association_proxy('player_notifications', 'notification', + creator=lambda notification: NotificationPlayer(notification=notification)) diff --git a/app/models/notification.py b/app/models/notification.py index 749e6b5..53ea321 100644 --- a/app/models/notification.py +++ b/app/models/notification.py @@ -16,5 +16,5 @@ class Notification(db.Model): 'NotificationPlayer', back_populates='notification', cascade='save-update, merge, delete, delete-orphan') - recipients = association_proxy('notification_recipients', 'player', - creator=lambda player: NotificationPlayer(recipient=player)) + recipients = association_proxy('notification_recipients', 'game_player', + creator=lambda game_player: NotificationPlayer(recipient=game_player)) diff --git a/app/models/notification_player.py b/app/models/notification_player.py index 00b6418..4ec8327 100644 --- a/app/models/notification_player.py +++ b/app/models/notification_player.py @@ -3,8 +3,8 @@ from app import db class NotificationPlayer(db.Model): __tablename__ = 'notification_player' notification_id = db.Column(db.Integer, db.ForeignKey('notification.id'), primary_key=True, nullable=False) - player_id = db.Column(db.Integer, db.ForeignKey('player.id'), primary_key=True, nullable=False) + game_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), primary_key=True, nullable=False) been_shown = db.Column(db.Boolean, server_default='True', nullable=False) notification = db.relationship('Notification', back_populates='notification_recipients') - recipient = db.relationship('Player', back_populates='player_notifications') + recipient = db.relationship('GamePlayer', back_populates='player_notifications') \ No newline at end of file