events WHERE name = 'Kaigi on Rails'; SELECT * FROM sessions WHERE event_id = 2 ORDER BY start_time ASC; 1 2 3 4 5 6 Events.find_by(name: 'Kaigi on Rai .sessions.order(:start_time) 1 2
FROM sessions WHERE event_id SELECT * FROM sessions WHERE event_id 1 2 3 4 Events.each do |event| p event.name event.sessions.each { p _1.speake end 1 2 3 4
SELECT * FROM sessions WHERE event_id IN (1, 2, . 1 2 3 4 Events.includes(:sessions).each do |e p event.name event.sessions.each { p _1.speaker end 1 2 3 4 クエリ2 回で完了!