From 5a3817cb16e526a7b18699a6dcdafe40c42c1ddf Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Tue, 25 Mar 2014 20:27:37 +0530 Subject: Fix Generation of proper migration when ActiveRecord::Base.pluralize_table_names = false. Previously, generation a migration like this: rails g migration add_column_name_to_user name would not generating the correct table name. Fixes #13426. --- activerecord/CHANGELOG.md | 13 +++++++++++++ .../active_record/migration/migration_generator.rb | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0f95a257ef..0cbb5c294b 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,16 @@ +* Fix Generation of proper migration when + ActiveRecord::Base.pluralize_table_names = false. + + Previously, generation a migration like this: + + rails g migration add_column_name_to_user name + + would not generating the correct table name. + + Fixes #13426. + + *Kuldeep Aggarwal* + * `touch` accepts many attributes to be touched at once. Example: diff --git a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb index 3968acba64..d3c853cfea 100644 --- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb +++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb @@ -23,16 +23,16 @@ module ActiveRecord case file_name when /^(add|remove)_.*_(?:to|from)_(.*)/ @migration_action = $1 - @table_name = $2.pluralize + @table_name = normalize_table_name($2) when /join_table/ if attributes.length == 2 @migration_action = 'join' - @join_tables = attributes.map(&:plural_name) + @join_tables = pluralize_table_names? ? attributes.map(&:plural_name) : attributes.map(&:singular_name) set_index_names end when /^create_(.+)/ - @table_name = $1.pluralize + @table_name = normalize_table_name($1) @migration_template = "create_table_migration.rb" end end @@ -61,6 +61,10 @@ module ActiveRecord raise IllegalMigrationNameError.new(file_name) end end + + def normalize_table_name(_table_name) + pluralize_table_names? ? _table_name.pluralize : _table_name.singularize + end end end end -- cgit v1.2.3