在Rails 4中向左外联接
我有3种型号: class Student < ActiveRecord::Base has_many :student_enrollments, dependent: :destroy has_many :courses, through: :student_enrollments end class Course < ActiveRecord::Base has_many :student_enrollments, dependent: :destroy has_many :students, through: :student_enrollments end class StudentEnrollment < ActiveRecord::Base belongs_to :student belongs_to :course end 我希望在“课程”表中查询课程列表,该列表在与某个学生相关联的“学生录取”表中不存在。 我发现也许使用Left Join是可行的方法,但似乎rails中的joins()仅接受一个表作为参数。我认为可以执行的SQL查询是: SELECT * FROM Courses c LEFT JOIN StudentEnrollment se ON c.id …