选择category_id,(从category.id = category_id类别中选择category.name)作为category_name(从(category.id = model.category_id)上的模型连接类别中选择distinct category_id作为category_id)作为R
... self.current_session.query(Model.category_id)。加入(类别).distinct()
但是如何知道category_name?
答案 0 :(得分:1)
for model, category in self.current_session.query(Model, Category).join(Category).distinct():
print model.category_id, category.name