Summing the size/count of associations for multiple records
Equivalent, but functional and idiomatic:

def total_leg_count
  active_flights_within_timeframe.includes(:legs).map { |fl| fl.legs.size }.sum
end


This pure SQL query should be equivalent and more performant:

def total_leg_count
  active_flights_within_timeframe.includes(:legs).count(:legs)
end