sqlalchemy - 使用声明性 SQLAlchemy 查询时失败:sa_exc.InvalidRequestError
问题描述
我正在使用 Python 3.9,SQLAlchemy 1.3.23。我正在尝试运行下面的查询(声明性),但它不起作用:
def get_user_rights_standard(self) -> List[Tuple[str, str, str]]:
return self.session.query(Employee, SvnRepo, SvnRight).\
with_entities(Employee.username.label("username"), SvnRepo.name.label("svn_repo"), SvnRight.name.label("svn_access_right")).\
join(SvnGroupMember, and_(SvnGroupMember.employee_id == Employee.id, SvnRepo.id == SvnGroupMember.repo_id)).\
join(SvnGroup, SvnGroup.id == SvnGroupMember.group_id).\
join(SvnRepoPathRight, and_(SvnGroupMember.group_id == SvnRepoPathRight.group_id, SvnGroupMember.repo_id == SvnRepoPathRight.repo_id, SvnRepoPathRight.right_id == SvnRight.id)).\
join(AuthzType, AuthzType.id == SvnRepo.authz_type_id).\
join(Path, Path.id == SvnRepoPathRight.path_id).\
filter(and_(AuthzType.name == "Standard", Employee.username is not None)).\
group_by(Employee.username).\
all()
错误消息说:
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Please use the .select_from() method to establish an explicit left side, as well as providing an explcit ON clause if not present already to help resolve the ambiguity.
我也尝试过select_from()
,但它从来没有用过,并且总是因同样的错误而失败。
如何解决?
我提前谢谢你。
问候,
杰克
解决方案
推荐阅读
- gremlin - 使用父顶点属性过滤掉正在运行的顶点
- c# - 如何使用对象返回 BadRequest?
- .net - TcpListener.AcceptSocket 什么时候应该优先于 TcpListener.AcceptTcpClient?
- php - 如何将关联数组项推入具有重复键的关联数组?
- c# - 用文件夹中的文件名填充 DataGridView
- java - 当我们可以使用 = 操作符复制对象时,为什么还要使用 clone()?
- html - 如何去除导航栏部分品牌名称的悬停效果?
- javascript - 使用 lit-html 用 Shadow DOM 封装自定义元素的 CSS
- google-maps - 谷歌融合表替代品
- python-3.x - 如何通过转换给定的两个数据框来生成新的数据框?