我正在尝试将这个“简单”的SQL语句映射到SQL-Alchemy
select DISTINCT cv.*, ct."name"
from "CarVariants" cv,
"Cars" ca,
"CarTypes" ct
where cv."f_keyNumber" = ca."keyNumber"
and cv."carType" = ca."carType"
and cv."carType" = ct."f_carType"
and "f_keyNumber" = '12345'
and "f_carId" = 1
这样的事情:
variants = self.em.CarVariants.createQuery();
variants = variants.filter_by(f_keyNumber=12345, f_carId = 1).distinct()
如何添加“和”关系(汽车,CarTypes)?
答案 0 :(得分:1)
使用and_
from sqlalchemy import and_
variants = variants.filter_by(and_(cond_1,cond_2....cond_n)).distinct()
请参阅此页面以获取进一步参考:
http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html