diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-03-25 16:03:51 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-03-25 16:03:51 +0100 |
commit | c35fb52c0cdd235cb69380df722c343ff5fa0bfa (patch) | |
tree | b22a9daaeb6b054d109f45da87b8a245c967b629 /activerecord | |
parent | 3fd15f484c2e0ddd8e4142d8c644767320920146 (diff) | |
parent | 5a3817cb16e526a7b18699a6dcdafe40c42c1ddf (diff) | |
download | rails-c35fb52c0cdd235cb69380df722c343ff5fa0bfa.tar.gz rails-c35fb52c0cdd235cb69380df722c343ff5fa0bfa.tar.bz2 rails-c35fb52c0cdd235cb69380df722c343ff5fa0bfa.zip |
Merge pull request #13440 from kuldeepaggarwal/pluralize_table_name_issue
Generating proper migration when ActiveRecord::Base.pluralize_table_names = false
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 13 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/migration_generator.rb | 10 |
2 files changed, 20 insertions, 3 deletions
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 |