diff options
Diffstat (limited to 'activerecord')
3 files changed, 15 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index c3aba63e1c..08c3917d7e 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -269,13 +269,15 @@ module ActiveRecord # remove_column(:suppliers, :qualification) # remove_columns(:suppliers, :qualification, :experience) def remove_column(table_name, *column_names) - if column_names.first.kind_of?(Enumerable) + if column_names.flatten! message = 'Passing array to remove_columns is deprecated, please use ' + 'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`' ActiveSupport::Deprecation.warn message, caller end - columns_for_remove(table_name, *column_names).each {|column_name| execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}" } + columns_for_remove(table_name, *column_names).each do |column_name| + execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}" + end end alias :remove_columns :remove_column diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 91929f80d2..00f74318c0 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -408,13 +408,13 @@ module ActiveRecord def remove_column(table_name, *column_names) #:nodoc: raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty? - if column_names.first.kind_of?(Enumerable) + if column_names.flatten! message = 'Passing array to remove_columns is deprecated, please use ' + 'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`' ActiveSupport::Deprecation.warn message, caller end - column_names.flatten.each do |column_name| + column_names.each do |column_name| alter_table(table_name) do |definition| definition.columns.delete(definition[column_name]) end diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 8dde6c6b5a..a448e0af9d 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -874,9 +874,17 @@ if ActiveRecord::Base.connection.supports_migrations? end def test_remove_column_with_array_as_an_argument_is_deprecated + ActiveRecord::Base.connection.create_table(:hats) do |table| + table.column :hat_name, :string, :limit => 100 + table.column :hat_size, :integer + table.column :hat_style, :string, :limit => 100 + end + assert_deprecated /Passing array to remove_columns is deprecated/ do - Person.connection.remove_column("people", ["last_name", "description"]) + Person.connection.remove_column("hats", ["hat_name", "hat_size"]) end + ensure + ActiveRecord::Base.connection.drop_table(:hats) end def test_change_type_of_not_null_column |