end • ͳͥ࿙ΕΔʁ ◦ ActiveRecord ͷ scope Λར༻͍ͯ͠Δ ◦ ༁modelࣄۀॴmodelͱͷؔ࿈͕͋Γɺʮࣄۀॴ.༁.scopeʯͱݺͼग़͢ҝ indexΘΕΔ ◦ joinͷ࣌ࣄۀॴใ͕ೖΒͳ͍ҝɺվળલͷΫΤϦͱͳΔ > ࣄۀॴ.༁.༁Ҏ্('2019-10-10') SELECT * FROM ༁ WHERE ༁.ࣄۀॴ_id = '111' AND ༁.༁ >= '2020-01-01' > ࣄۀॴ.औҾ.joins(༁).merge(༁.༁Ҏ্('2019-10-10')) SELECT * FROM औҾ ɹINNER JOIN ༁ ON ༁.औҾ_id = औҾ.id WHERE औҾ.ࣄۀॴ_id = '111' AND ༁.༁ >= '2020-01-01' ༁model scope :༁Ҏ্, ->(ࣄۀॴ_id, ) do where('ࣄۀॴ_id = ? AND ༁ΧϥϜ >= ?', ࣄۀॴ_id, ) end > ࣄۀॴ.औҾ.joins(༁).merge(༁.༁Ҏ্(111, '2019-10-10')) SELECT * FROM औҾ ɹINNER JOIN ༁ ON ༁.औҾ_id = औҾ.id WHERE ɹऔҾ.ࣄۀॴ_id = '111' AND ༁.ࣄۀॴ_id = '111' AND ༁.༁ >= '2020-01-01' DBपΓͷύϑΥʔϚϯεվળ