jeudi 23 février 2017

INNER JOIN on a table using more than one column, rails associations

I have association in rails 3.2,

has_many :skills, :dependent => :destroy,

I wanted to add a join with a condition in the above association,

skills = user.skills.joins('INNER JOIN user_skills ON skills.id = user_skills.skill_id and skills.account_id = user_skills.account_id')

So instead of using user.skills.joins(). I only wanted to use user.skills. Scope is also one option but is it possible to add that in association.

Aucun commentaire:

Enregistrer un commentaire