aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/rails
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-07-18 23:04:00 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2012-07-18 23:04:00 -0700
commit993e1643650b7b0939437f86b7b4cda0d92b0b8f (patch)
treeda6e1e28ba351c4cf8d88acb0064a204a0ae4a74 /activerecord/lib/rails
parente482100d6ed022d00ba31c6c4377f6f947173337 (diff)
parent5a7d31913bb16977ec85d55de34ac0d79b512d62 (diff)
downloadrails-993e1643650b7b0939437f86b7b4cda0d92b0b8f.tar.gz
rails-993e1643650b7b0939437f86b7b4cda0d92b0b8f.tar.bz2
rails-993e1643650b7b0939437f86b7b4cda0d92b0b8f.zip
Merge pull request #7097 from lexmag/join_table_gen_attr
Add fkey attributes to `join_table` migration generator
Diffstat (limited to 'activerecord/lib/rails')
-rw-r--r--activerecord/lib/rails/generators/active_record/migration/migration_generator.rb12
1 files changed, 10 insertions, 2 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 c1f9d8962b..f6a432c6e5 100644
--- a/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
@@ -21,7 +21,7 @@ module ActiveRecord
when /join_table/
if attributes.length == 2
@migration_action = 'join'
- @join_tables = attributes.map(&:name)
+ @join_tables = attributes.map(&:plural_name)
set_index_names
end
@@ -30,9 +30,17 @@ module ActiveRecord
def set_index_names
attributes.each_with_index do |attr, i|
- attr.index_name = [attr, attributes[i - 1]].map{ |a| :"#{a.name.singularize}_id"}
+ attr.index_name = [attr, attributes[i - 1]].map{ |a| index_name_for(a) }
end
end
+
+ def index_name_for(attribute)
+ if attribute.foreign_key?
+ attribute.name
+ else
+ attribute.name.singularize.foreign_key
+ end.to_sym
+ end
end
end
end