From a724096ca5f0d40914fe2310da898477f5835e75 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 16 Mar 2013 14:51:52 -0700 Subject: factory methods should not alter object state --- .../connection_adapters/abstract/schema_definitions.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3