我有这张桌子:
channel_items = Table(
"channel_items",
metadata,
Column("channel_id", Integer, ForeignKey("channels.id")),
Column("media_item_id", Integer, ForeignKey("media_items.id"))
)
class Channel(rdb.Model):
"""Set up channels table in the database"""
rdb.metadata(metadata)
rdb.tablename("channels")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
items = relationship("MediaItem", secondary=channel_items, order_by="MediaItem.titleView", backref="channels")
class MediaItem(rdb.Model):
"""Set up items table in the database"""
rdb.metadata(metadata)
rdb.tablename("media_items")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
type = Column("type", String(50))
我想进行查询,但过滤第二个表。类似的东西:
channels = session.query(Channel).options(eagerload(“item”))。filter(MediaItem ==“jpg”)。all()
提前致谢!
答案 0 :(得分:0)
您只需通过关系名称引用它。此外,它在您的计划中的“项目”,而不是“项目”。
channels = session.query(Channel).options(eagerload("items")).filter(Channel.items.type == "jpg").all()