SkRoR
SkRoR

Reputation: 1199

How to write using where and and conditions on active record rails

how to write this query using where and and conditions on active record rails

SELECT c.name FROMcategoriesas 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

Answers (1)

K M Rakibul Islam
K M Rakibul Islam

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

Related Questions