From db33cf8f20c5576b1ee7325545b608967066edcf Mon Sep 17 00:00:00 2001 From: Burathar Date: Sat, 18 Jul 2020 22:16:14 +0200 Subject: [PATCH] Replace relation between user and player_caught_player with game_player and player_caught_player --- app/models/game_player.py | 17 ++++++++++++++++- app/models/player_caught_player.py | 8 ++++---- app/models/user.py | 16 +--------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/models/game_player.py b/app/models/game_player.py index c7f66b6..f194c49 100644 --- a/app/models/game_player.py +++ b/app/models/game_player.py @@ -1,7 +1,7 @@ from sqlalchemy.ext.associationproxy import association_proxy from app import db -from app.models import Role, NotificationPlayer, PlayerFoundObjective +from app.models import Role, NotificationPlayer, PlayerFoundObjective, PlayerCaughtPlayer class GamePlayer(db.Model): __tablename__ = 'game_player' @@ -26,3 +26,18 @@ class GamePlayer(db.Model): found_objectives = association_proxy('player_found_objectives', 'objective', creator=lambda objective: PlayerFoundObjective(objective=objective)) + player_caught_players = db.relationship( + 'PlayerCaughtPlayer', + back_populates='catching_player', + cascade='save-update, merge, delete, delete-orphan', + foreign_keys=[PlayerCaughtPlayer.catching_player_id]) + caught_players = association_proxy('player_caught_players', 'game_player', + creator=lambda game_player: PlayerCaughtPlayer(caught_player=game_player)) + + player_caught_by_players = db.relationship( + 'PlayerCaughtPlayer', + back_populates='caught_player', + cascade='save-update, merge, delete, delete-orphan', + foreign_keys=[PlayerCaughtPlayer.caught_player_id]) + caught_by_players = association_proxy('player_caught_by_players', 'game_player', + creator=lambda game_player: PlayerCaughtPlayer(catching_player=game_player)) diff --git a/app/models/player_caught_player.py b/app/models/player_caught_player.py index f6eb5ec..4de2854 100644 --- a/app/models/player_caught_player.py +++ b/app/models/player_caught_player.py @@ -5,10 +5,10 @@ from app import db class PlayerCaughtPlayer(db.Model): __tablename__ = 'player_caught_player' id = db.Column(db.Integer, primary_key=True, autoincrement=True, server_default='-1') - catching_player_id = db.Column(db.Integer, db.ForeignKey('player.id'), nullable=False) - caught_player_id = db.Column(db.Integer, db.ForeignKey('player.id'), nullable=False) + catching_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), nullable=False) + caught_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), nullable=False) photo_reference = db.Column(db.String(128), unique=True, nullable=False) timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False) - catching_player = db.relationship('Player', back_populates='player_caught_by_players', foreign_keys=[catching_player_id]) - caught_player = db.relationship('Player', back_populates='player_caught_players', foreign_keys=[caught_player_id]) + catching_player = db.relationship('GamePlayer', back_populates='player_caught_by_players', foreign_keys=[catching_player_id]) + caught_player = db.relationship('GamePlayer', back_populates='player_caught_players', foreign_keys=[caught_player_id]) \ No newline at end of file diff --git a/app/models/user.py b/app/models/user.py index 6bfac8b..2262a52 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -26,21 +26,7 @@ class User(UserMixin, db.Model): - player_caught_players = db.relationship( - 'PlayerCaughtPlayer', - back_populates='catching_player', - cascade='save-update, merge, delete, delete-orphan', - foreign_keys=[PlayerCaughtPlayer.catching_player_id]) - caught_players = association_proxy('player_caught_players', 'player', - creator=lambda player: PlayerCaughtPlayer(caught_player=player)) - - player_caught_by_players = db.relationship( - 'PlayerCaughtPlayer', - back_populates='caught_player', - cascade='save-update, merge, delete, delete-orphan', - foreign_keys=[PlayerCaughtPlayer.caught_player_id]) - caught_by_players = association_proxy('player_caught_by_players', 'player', - creator=lambda player: PlayerCaughtPlayer(catching_player=player)) + locations = db.relationship( 'Location',