Browse Source

Replace relation between user and player_caught_player with game_player and player_caught_player

testing
Burathar 5 years ago
parent
commit
db33cf8f20
  1. 17
      app/models/game_player.py
  2. 8
      app/models/player_caught_player.py
  3. 16
      app/models/user.py

17
app/models/game_player.py

@ -1,7 +1,7 @@ @@ -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): @@ -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))

8
app/models/player_caught_player.py

@ -5,10 +5,10 @@ from app import db @@ -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])

16
app/models/user.py

@ -26,21 +26,7 @@ class User(UserMixin, db.Model): @@ -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',

Loading…
Cancel
Save