diff options
author | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-03-25 20:27:37 +0530 |
---|---|---|
committer | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-03-25 20:27:37 +0530 |
commit | 5a3817cb16e526a7b18699a6dcdafe40c42c1ddf (patch) | |
tree | b22a9daaeb6b054d109f45da87b8a245c967b629 /activerecord/lib/rails/generators | |
parent | 3fd15f484c2e0ddd8e4142d8c644767320920146 (diff) | |
download | rails-5a3817cb16e526a7b18699a6dcdafe40c42c1ddf.tar.gz rails-5a3817cb16e526a7b18699a6dcdafe40c42c1ddf.tar.bz2 rails-5a3817cb16e526a7b18699a6dcdafe40c42c1ddf.zip |
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.
Diffstat (limited to 'activerecord/lib/rails/generators')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/migration_generator.rb | 10 |
1 files changed, 7 insertions, 3 deletions
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 |