我正在使用 Eve-SQLAlchemy == 0.5.0
我想在我的用户上使用Postman执行嵌套查询,以便找到指定组织内的所有用户。
使用SQL我会编写我的查询:
InitializeTestPatientInfo(Gender: true);
我有一个用户模型,一个组织模型和一个链接两个user_organization的关系模型。
select * from app_user
left join user_organization on user_organization.user_id = app_user.id
left join organization on organization.id = user_organization.organization_id
where organization.id = 2
在我的settings.py中,我注册了资源:
from sqlalchemy import Column, DateTime, func, String, Integer
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class BaseModel(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
__abstract__ = True
_created = Column(DateTime, default=func.now())
_updated = Column(DateTime, default=func.now(), onupdate=func.now())
_etag = Column(String(40))
class User(BaseModel):
__tablename__ = 'app_user'
organizations = relationship("Organization", secondary=UserOrganization.__tablename__)
class Organization(BaseModel):
__tablename__ = 'organization'
name = Column(String)
class UserOrganization(BaseModel):
__tablename__ = 'user_organization'
user_id = Column(Integer,
ForeignKey('app_user.id', ondelete='CASCADE'))
organization_id = Column(Integer,
ForeignKey('organization.id', ondelete='CASCADE'))
我有一系列邮递员收藏设置,并且使用GET请求我可以轻松查询任何属性... # Resource Registration
DOMAIN = DomainConfig({
'organization': ResourceConfig(Organization),
'user': ResourceConfig(User)
}).render()
我尝试过(在许多其他事情中):
GET localhost:5000/user?where={"id":1}
答案 0 :(得分:3)
由于一个错误,目前似乎不可能。我将在下周内尝试修复它。
https://github.com/pyeve/eve-sqlalchemy/blob/master/eve_sqlalchemy/parser.py#L73中的代码导致GET ?where={"organizations": 2}
导致生成user_id = 42 AND organization_id = 42
之类的SQL表达式。这很少有意义。