diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-16 14:51:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-03-22 16:22:00 -0700 |
commit | a724096ca5f0d40914fe2310da898477f5835e75 (patch) | |
tree | 574d60f797bb2b163ab14ab701da291baae2e501 /activerecord | |
parent | 14d7dc0811fc946ffb63ceed7e0389ed14b50800 (diff) | |
download | rails-a724096ca5f0d40914fe2310da898477f5835e75.tar.gz rails-a724096ca5f0d40914fe2310da898477f5835e75.tar.bz2 rails-a724096ca5f0d40914fe2310da898477f5835e75.zip |
factory methods should not alter object state
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 8f79cc17fe..ebf9a662c3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -217,7 +217,12 @@ module ActiveRecord raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table." end - column = self[name] || new_column_definition(name, type) + column = @columns_hash.fetch(name) { + col = new_column_definition(name, type) + @columns << col + @columns_hash[name] = col + col + } limit = options.fetch(:limit) do native[type][:limit] if native[type].is_a?(Hash) @@ -273,10 +278,7 @@ module ActiveRecord end def new_column_definition(name, type) - definition = create_column_definition name, type - @columns << definition - @columns_hash[name] = definition - definition + create_column_definition name, type end def primary_key_column_name |