title: Status model design pattern
body: <p>I'm running into problems implementing statuses for a model. This is probably due to wrong design.</p>
  
  <p>There is a model which has a status. There can be multiple instances of the model and only a few predefined statuses (like: created, renewed, retrieved etc.). For each individual status there is some calculation logic for the model. E.g. <code>model.cost()</code> is differently calculated for each status.</p>
  
  <p>I'd like to have ActiveRecord automatically set the correct <code>model_status_id</code> when saving a model. I think in the ideal situation I could do something like this:</p>
  
  <pre><code>model.status = StatusModel.retrieved
  </code></pre>
  
  <p>and</p>
  
  <pre><code>case status
    when renewed
      # ...
    when retrieved
      # ..
  end
  </code></pre>
  
  <p>Thinking i need to save the status in the model row in the database this is what i've got now:</p>
  
  <pre><code>ModelStatus &lt; ActiveRecord::Base
    has_many :models
  Model &lt; ActiveRecord::Base
    belongs_to :model_status
  </code></pre>
  
  <p>However this is giving me a lot of issues in the code. Anyone having some good ideas or patterns for this?</p>