title: Why does activerecord not populate an auto-incrementing column in the item returned from a create?
body: <p>Why does rails not populate an auto-incrementing column in the item returned from a create? Is there a better way to do this?</p>
  
  <p>In rails, when you do <code>a = Foo.create</code> then <code>a.id</code> is populated</p>
  
  <p>But if you have a field that was created via </p>
  
  <pre><code>def up   
    execute "ALTER TABLE my_table ADD COLUMN my_auto_incrementing_column INTEGER AUTO_INCREMENT not null UNIQUE KEY;"
  end
  </code></pre>
  
  <p>Then that field does not appear when you use create. You have to use a reload also.</p>
  
  <pre><code>a = Foo.create
  a.id # not nil
  a.my_auto_incrementing_column # nil
  a.reload
  a.my_auto_incrementing_column # is now populated
  </code></pre>
  
  <p>Version information:</p>
  
  <pre><code>$ ruby -v
  ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin14.5.0]
  $ bundle exec rails -v
  Rails 3.2.12
  $ mysql --version
  mysql  Ver 14.14 Distrib 5.6.26, for osx10.10 (x86_64) using  EditLine wrapper
  </code></pre>
  
  <p>Some background: </p>
  
  <p>This code is being applied to a large existing in-production rails codebase that requires that all id fields be UUIDs. The auto_increment column is not a primary key, because it was added after we had discovered that a new external integration partner could not handle using our existing long unique identifiers (UUIDs). </p>
  
  <p>We are working hard to update our version of ruby but we don't want to wait for that as a solution to this problem. Also, after reading changelogs in activerecord, I still don't have proof that any future version of ruby/rails will contain a bugfix for this problem.</p>
  
  <p>The code which I want to improve:</p>
  
  <pre><code>class Foo &lt; ActiveRecord::Base
    has_one :object_containing_auto_incrementing_column
  
    def my_method
      if self.object_containing_auto_incrementing_column.nil?
        self.object_containing_auto_incrementing_column = ObjectContainingAutoIncrementingColumn.create(owner: self)
        self.object_containing_auto_incrementing_column.reload
      end
      self.object_containing_auto_incrementing_column.my_auto_incrementing_column
    end
  end
  </code></pre>