度日eagerload_all()在一定時間內的孩子我有一個表帖子它存儲3種後,主題,回覆和評論。每個人都有其父母ID。如何設置過濾器在SQLAlchemy的
# Single table inheritance
class Post(Base):
__tablename__ = 'posts'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('posts.id'))
discriminator = Column(String(1))
content = Column(UnicodeText)
added_at = Column(DateTime)
__mapper_args__ = {'polymorphic_on': discriminator}
class Topic(Post):
replies = relation("Reply")
__mapper_args__ = {'polymorphic_identity': 't'}
class Reply(Post):
comments = relation("Comment")
__mapper_args__ = {'polymorphic_identity': 'r'}
class Comment(Post):
__mapper_args__ = {'polymorphic_identity': 'c'}
而且我使用eagerload_all()來獲取所有的答覆和意見屬於一個話題:
session.query(Topic).options(eagerload_all('replies.comments')).get(topic_id)
我的問題是,如果我想只得到答覆和這些答覆的意見在某個時間段內,例如,本週或本月。我應該如何使用過濾器來實現這一目標?
謝謝