你如何比较一对多 SQLAlchemy 关系的日期?
基本上对于我的模型结构,Team 和 Player 之间存在一对多的关系:
class Team(db.Model):
__tablename__ = 'Team'
id = db.Column(db.Integer, primary_key=True)
players = db.relationship('Player', backref='team', lazy='dynamic')
class Player(db.Model):
__tablename__ = 'Player'
id = db.Column(db.Integer, primary_key=True)
last_match = db.Column(db.DateTime)
team_id = db.Column(db.Integer, db.ForeignKey('Team.id'))
所以我想找到一个团队的所有最近的球员过去某个日期,但我试过的没有奏效:
team = Team.query.filter_by(id=some_id).first()
recent_players = team.players.filter(Players.last_match.date() > some_date)
我究竟做错了什么?