|
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
from .game_player import GamePlayer
|
|
|
|
|
|
|
|
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('game_player.id'), nullable=False)
|
|
|
|
caught_player_id = db.Column(db.Integer, db.ForeignKey('game_player.id'), nullable=False)
|
|
|
|
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False)
|
|
|
|
catching_player = db.relationship('GamePlayer', primaryjoin=(catching_player_id == GamePlayer.id),
|
|
|
|
backref=db.backref('player_caught_players', cascade='save-update, merge, delete, delete-orphan'))
|
|
|
|
caught_player = db.relationship('GamePlayer', primaryjoin=(caught_player_id == GamePlayer.id),
|
|
|
|
backref=db.backref('player_caught_by_players', cascade='save-update, merge, delete, delete-orphan'))
|
|
|
|
|
|
|
|
'''
|
|
|
|
This relation doesn't work as well as the others, and must be used as folowed:
|
|
|
|
g = Game.query.first()
|
|
|
|
p1 = User.query[2].player_in(g)
|
|
|
|
p2 = User.query[3].player_in(g)
|
|
|
|
pc = PlayerCaughtPlayer(caught_player=p2, catching_player=p1)
|
|
|
|
db.session.add(pc)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
'''
|