From 211d88b71b3df2ae161b23579a79f8e937132388 Mon Sep 17 00:00:00 2001 From: Aleksey Magusev Date: Wed, 11 Jul 2012 01:38:21 +0400 Subject: Add join table migration generator For instance, running rails g migration CreateMediaJoinTable artists musics:uniq will create a migration with create_join_table :artists, :musics do |t| # t.index [:artist_id, :music_id] t.index [:music_id, :artist_id], unique: true end --- railties/lib/rails/generators/generated_attribute.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/generators/generated_attribute.rb') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index d480fc12b5..35cd40d25e 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -8,6 +8,7 @@ module Rails attr_accessor :name, :type attr_reader :attr_options + attr_writer :index_name class << self def parse(column_definition) @@ -94,7 +95,7 @@ module Rails end def index_name - if reference? + @index_name ||= if reference? polymorphic? ? %w(id type).map { |t| "#{name}_#{t}" } : "#{name}_id" else name -- cgit v1.2.3