I found this loop was a little more optimal:
```
@postcode_courts = PostcodeCourt.include(:court).all
        CSV.generate do |csv|
          csv << ["Post code", "Court number", "Court name"]
          @postcode_courts.each do |postcode|
            csv << [postcode.postcode, postcode.court.name, postcode.court.cci_code ? postcode.court.cci_code : postcode.court.court_number]
          end
        end
```