diff options
author | Aleksey Magusev <lexmag@gmail.com> | 2012-07-19 00:24:21 +0400 |
---|---|---|
committer | Aleksey Magusev <lexmag@gmail.com> | 2012-07-19 00:24:21 +0400 |
commit | 5a7d31913bb16977ec85d55de34ac0d79b512d62 (patch) | |
tree | fe178a7dc9532832a8ec8ea992f28a29cae61320 /railties | |
parent | fe5b943d9fd389f313dd87bf73b7c11b8746227b (diff) | |
download | rails-5a7d31913bb16977ec85d55de34ac0d79b512d62.tar.gz rails-5a7d31913bb16977ec85d55de34ac0d79b512d62.tar.bz2 rails-5a7d31913bb16977ec85d55de34ac0d79b512d62.zip |
Add fkey attributes to `join_table` migration generator
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 10 | ||||
-rw-r--r-- | railties/test/generators/migration_generator_test.rb | 2 |
2 files changed, 10 insertions, 2 deletions
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| |