Reputation: 1199
how to write this query using where and and conditions on active record rails
SELECT c.name FROM
categoriesas c join categories_coaches as cc on cc.category_id=c.id where cc.coach_id=16 and c.parent_id=1
Upvotes: 1
Views: 52
Reputation: 34318
This should do it:
Category.joins(:categories_coaches)
.where('categories_coaches.id = ? AND categories.parent_id = ?', 16, 1)
.select('categories.name')
Upvotes: 1