I have two models, Users and Leads connected with HABTM relation:
Users
Leads
class Lead < ActiveRecord::Base has_and_belongs_to_many :use
You can use a left join. Assuming your join table is named leads_users:
leads_users
Lead.joins('LEFT JOIN leads_users ON leads_users.lead_id = leads.id'). where(leads_users: { user_id: nil })