class Items(Base):
tag_id = Column(Integer, ForeignKey(Tag.id, ondelete='CASCADE'), index=True)
...
tag = relationship('Tag', back_populates='items')
query = Select(Items)
cursor = await db_session.execute(query)
items = cursor.scalars().all()
print(items[0].tag.id) # 123
为什么没有
joinedload
它也能工作?第二个表的额外查询什么时候发生?
可能是因为这个Tag对象已经在会话缓存中了