LEFT OUTER JOIN in Rails 4

前端 未结 12 1741
一整个雨季
一整个雨季 2020-11-28 09:44

I have 3 models:

class Student < ActiveRecord::Base
  has_many :student_enrollments, dependent: :destroy
  has_many :courses, through: :student_enrollment         


        
12条回答
  •  自闭症患者
    2020-11-28 10:05

    I know that this is an old question and an old thread but in Rails 5, you could simply do

    Course.left_outer_joins(:student_enrollments)
    

提交回复
热议问题