title: Better way to build has_one association or update if it exists
body: <p>My discount class has a sales_period. I want to write a method which can build this association when it does not exist, or updates it when it does exist. Currently I am writing the following if condition.</p>
  
  <pre><code>class Discount &lt; ActiveRecord::Base
    has_one :sales_period
  
    def fetch_period
      end_date = ...
      if sales_period.nil?
        build_sales_period( end: end_date )
      else
        sales_period.end = end_date
      end
    end
  end
  </code></pre>
  
  <p>Is there a better way to do this, similar to <code>find_or_create</code>?</p>