title: Rails - Validate unique month in year
body: <p>Using Rails 6.</p>
  
  <p>I have a model, <code>MonthlyConsumption</code>, which is a measure of a monthly energy consumption. It contains the following fields:</p>
  
  <ul>
  <li><code>month</code> as an integer from 1-12; This is later converted into a month using some key-value pairs e.g <code>1: 'January'</code></li>
  <li><code>year</code>: an integer, e.g <code>2020</code></li>
  <li><code>amount</code>: an integer, the amount of power consumption in kW</li>
  <li><code>city_id</code>: A reference to a <code>City</code> model</li>
  </ul>
  
  <p>I want to validate that there is only 1 possible entry in one month of a given year, per city.</p>
  
  <p>For example:</p>
  
  <ul>
  <li><code>500kW in January 2020 in City X</code> &amp; <code>600kW in January 2021 in City X</code> should both be valid</li>
  <li><code>500kW in January 2020 in City X</code> &amp; <code>600kW in January 2020 in City Y</code> should both be valid</li>
  <li><code>500kW in January 2020 in City X</code> &amp; <code>600kW in January 2020 in City X</code> should be invalid</li>
  </ul>
  
  <p>What would be the best way of accomplishing this validation?</p>