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?
Give this a whirl;
Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With