Reputation: 917
I have 2 models (Workout, Equipment) in a has and belongs to many relationship. If I use Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = 5")
it works, but if I use Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = null")
it doesn't return the records with no association. Any ideas?
Upvotes: 9
Views: 4197
Reputation: 2293
Give this a whirl;
Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null")
Upvotes: 11