我正在尝试sqlalchemy-ize以下查询:
select feat.*, array_remove(array_agg(fa), null) as assets, array_remove(array_agg(fs), null) as styles
from features as feat
LEFT JOIN feature_assets fa on feat.id = fa.feature_id
LEFT JOIN feature_styles fs on feat.id = fs.feature_id
where project_id = :projectId
group by feat.id
到目前为止,我抛出的错误是这样的:
sqlalchemy.exc.ArgumentError: Object <class 'FeatureStyle'> is not legal as a SQL literal value
这段代码:
db_session.query(
[
Feature,
func.array_remove(func.array_agg(FeatureStyle), None),
func.array_remove(func.array_agg(FeatureAsset), None)
]
).outerjoin(FeatureAsset)\
.outerjoin(FeatureStyle)\
.filter(Feature.project_id == projectId)\
.group_by(Feature.id)
原始SQL查询有效。有一些聪明的方法来修复该sqlalchemy查询吗?