aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorKuldeep Aggarwal <kd.engineer@yahoo.co.in>2014-03-25 20:27:37 +0530
committerKuldeep Aggarwal <kd.engineer@yahoo.co.in>2014-03-25 20:27:37 +0530
commit5a3817cb16e526a7b18699a6dcdafe40c42c1ddf (patch)
treeb22a9daaeb6b054d109f45da87b8a245c967b629 /activerecord
parent3fd15f484c2e0ddd8e4142d8c644767320920146 (diff)
downloadrails-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')
-rw-r--r--activerecord/CHANGELOG.md13
-rw-r--r--activerecord/lib/rails/generators/active_record/migration/migration_generator.rb10
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