title: How to update the sort order of my models when the position changes
body: <p>So I have a list of products, say 50 of them.</p>
  
  <pre><code>def reorder_products(products, product_id, product_index) do
  end
  </code></pre>
  
  <p>The products is a list of ecto Product model schemas, that has a sort_order property.</p>
  
  <p>So in the UI the user can drag a product and change the sort order of a given product.  I need to update the records above or below whereever the user wants to insert the product.</p>
  
  <p>So to visual this:</p>
  
  <pre><code>id   sort_order
  1    1000
  2    2000
  3    3000
  4    4000
  5    5000
  </code></pre>
  
  <p>So if the product#5 gets reordered and placed at index position 3, the new list will look like:</p>
  
  <pre><code>id   sort_order
  1    1000
  2    2000
  5    5000
  3    3000
  4    4000
  </code></pre>
  
  <p>So now I have to reorder all rows below that (ignoring the fact I could just change the sort order without changing the others for now)</p>
  
  <p>How could I do that in ecto?</p>
  
  <p>In another language I would do:</p>
  
  <pre><code>for(x = 0; x &lt; products.length(); x++)
  {
      if x &gt;= 3 {
        products[x].sort_order = x * 1000;
        products[x].save!
      }
  }
  </code></pre>
  
  <p>In elixir I would do this, but the ordering is not guaranteed.</p>
  
  <pre><code>Enum.map(products, fn p -&gt; 
     p.sort_order = ???  # i need the index position here
  end)
  </code></pre>