From 5a7d31913bb16977ec85d55de34ac0d79b512d62 Mon Sep 17 00:00:00 2001 From: Aleksey Magusev Date: Thu, 19 Jul 2012 00:24:21 +0400 Subject: Add fkey attributes to `join_table` migration generator --- railties/lib/rails/generators/generated_attribute.rb | 10 +++++++++- railties/test/generators/migration_generator_test.rb | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 35cd40d25e..d2c2abf40c 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -90,8 +90,12 @@ module Rails end end + def plural_name + name.sub(/_id$/, '').pluralize + end + def human_name - name.to_s.humanize + name.humanize end def index_name @@ -102,6 +106,10 @@ module Rails end end + def foreign_key? + !!(name =~ /_id$/) + end + def reference? self.class.reference?(type) end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 9f9cd9c9fc..774038c0e1 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -169,7 +169,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase def test_create_join_table_migration migration = "add_media_join_table" - run_generator [migration, "artists", "musics:uniq"] + run_generator [migration, "artist_id", "musics:uniq"] assert_migration "db/migrate/#{migration}.rb" do |content| assert_method :change, content do |up| -- cgit v1.2.3