9

我有 2 个模型(锻炼、设备),并且属于许多关系。如果我使用Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = 5")它可以工作,但如果我使用Workout.find(:all, :joins => :equipment, :conditions => "equipment.id = null")它不会返回没有关联的记录。有任何想法吗?

4

1 回答 1

11

试一试;

Workout.joins("left join equipments e on workouts.id = e.workouts_id").where("e.id is null")
于 2012-07-01T03:47:20.200 回答