Rails: HABTM - find all records without association

I have 2 models (Workout, Equipment) that have and belong to many relationships. 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 does not return records without association. Any ideas?

+6
source share
1 answer

Give it a whirlwind;

 Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null") 
+9
source

Source: https://habr.com/ru/post/919412/


All Articles