如何使用活动记录轨道上的where和条件来编写此查询
SELECT c.name FROM
类别as c join categories_coaches as cc on cc.category_id=c.id where cc.coach_id=16 and c.parent_id=1
答案 0 :(得分:1)
这应该这样做:
Category.joins(:categories_coaches)
.where('categories_coaches.id = ? AND categories.parent_id = ?', 16, 1)
.select('categories.name')