我有以下实体。当我api/event/1
时,我会收到invitation
,但不包含invitationResponses
。是否以及如何实现这一目标?
当我api/invitation/1
时,会包含邀请响应。
class Person(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(64), index = True)
owner = db.Column(db.Integer, db.ForeignKey('user.id'))
description = db.Column(db.String(128))
start = db.Column(db.DateTime)
end = db.Column(db.DateTime)
invitation = db.relationship('Invitation', uselist=False, backref = db.backref('event', uselist=False))
class Invitation(db.Model):
id = db.Column(db.Integer, primary_key = True)
event_id = db.Column(db.Integer, db.ForeignKey('event.id'))
sent = db.Column(db.DateTime)
expires = db.Column(db.DateTime)
invitationResponses = db.relationship('InvitationResponse', backref = db.backref('invitation', uselist=False))
class InvitationResponse(db.Model):
id = db.Column(db.Integer, primary_key = True)
invitation_id = db.Column(db.Integer, db.ForeignKey('invitation.id'))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
attending = db.Column(db.Boolean)