Arelのススメ -- JOINをArelで書こう

今回は特によく使うけれども書き方がよくわからないJOIN句を取り上げます。 対象とするテーブル/モデル 今回は以下のモデルを例にJOIN句を作成してみます。 Student: 学生 Exam: 試験 学生は複数の試験を課される Railsであれば以下のようなAssociationを定義するのが普通です。 class Student < ApplicationRecord has_many :exams end class Exam < ApplicationRecord belongs_to :student end このように has_many , belongs_to を定義しておけば、Arelを … 続きを読む Arelのススメ -- JOINをArelで書こう