Join tables connected through join through

I have 3 tables.

This is just simple representation of relations.

 User (many to many :roles  join through :user_roles)
 Role (many to many :users join through :user_roles)
 Role(belongs_to :prof)

I want to filter out users where prof meets specific condition.

But I am confused about how to join these three . The confusion is how i combine the user and role table.
Thanks.