使用 notlike
过滤器时,此语句有效:
result = self.session.query(PropMetadata, FloorPlan).join(FloorPlan,
FloorPlan.prop_metadata_id == PropMetadata.id).\
filter(FloorPlan.rent_range.notlike('%Call%'))
使用 ==
过滤器时,此语句有效(floorplan 正在传递到我的函数中):
result = self.session.query(PropMetadata, FloorPlan).join(FloorPlan,
FloorPlan.prop_metadata_id == PropMetadata.id).\
filter(FloorPlan.layout == floorplan)
与 and_
结合使用时,出现此错误:
result = self.session.query(PropMetadata, FloorPlan).join(FloorPlan,
FloorPlan.prop_metadata_id == PropMetadata.id).\
filter(and_(
FloorPlan.rent_range.notlike('%Call%'),
FloorPlan.layout == floorplan
))
sqlalchemy.exc.ArgumentError: Mapped instance expected for relationship
comparison to object. Classes, queries and other SQL elements are not
accepted in this context; for comparison with a subquery, use
FloorPlan.prop_metadata.has(**criteria).
我该如何解决这个问题?