title: Rails two way association
body: <p>I've implemented a model with <code>modified_by_id</code> and <code>modifies_id</code> self-referencing attributes to persist "dirty" state of some models.</p>
  
  <pre class="lang-rb prettyprint-override"><code>class CreateModels &lt; ActiveRecord::Migration[5.0]
    def change
      create_table :models do |t|
        t.string :name
        t.modified_by_id :integer
        t.modifies_id :integer
      end
    end
  end
  </code></pre>
  
  <p>This double association has the intention of speeding (and simplifying) two queries</p>
  
  <ul>
  <li>the latest version of things <code>where(modified_by_id: nil)</code></li>
  <li>the persisted version of things <code>where(modifies_id: nil)</code></li>
  </ul>
  
  <p>Everything works well when handling the ids manually, but I can't model it properly with relations.</p>
  
  <pre class="lang-rb prettyprint-override"><code>    has_one :modifies, class_name: 'Some::Model', foreign_key: 'modifies_id'
    belongs_to :modified_by, class_name: 'Some::Model', foreign_key: 'modified_by_id'
  </code></pre>
  
  <p>Using it so populates only one of the ids when calling <code>model.modifies = new_model</code></p>
  
  <p>And this:</p>
  
  <pre class="lang-rb prettyprint-override"><code> has_one :modifies, class_name: 'Some::Model', foreign_key: 'modifies_id'
    belongs_to :modified_by, class_name: 'Some::Model', inverse_of: :modifies, foreign_key: 'modified_by_id'
  </code></pre>
  
  <p>pupulates only one model with the same id twice (modifes_id == modofies_by_id)</p>
  
  <p>How should this be modeled?</p>