我有以下SQLAlchemy映射的类:
class User(Base):
__tablename__ = 'users'
email = Column(String, primary_key=True)
name = Column(String)
class Document(Base):
__tablename__ = "documents"
name = Column(String, primary_key=True)
author = Column(String, ForeignKey("users.email"))
class DocumentsPermissions(Base):
__tablename__ = "documents_permissions"
readAllowed = Column(Boolean)
writeAllowed = Column(Boolean)
document = Column(String, ForeignKey("documents.name"))
我需要为这样的一张桌子user.email = "user@email.com"
:
email | name | document_name | document_readAllowed | document_writeAllowed
如何使用一个SQLAlchemy查询请求进行查询?以下代码对我不起作用:
result = session.query(User, Document, DocumentPermission).filter_by(email = "user@email.com").all()
谢谢,
当我执行类似的任务时,我得到SyntaxError:关键字不能是表达式
—
Ishan Tomar
result = session.query(User, Document).select_from(join(User, Document)).filter(User.email=='user@email.com').all()
但是我还没有设法使三个表(包括DocumentPermissions)相似。任何想法?