diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-04-20 22:13:17 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-04-20 22:13:17 +0200 |
commit | 3ff6b800f2fc3552d98a0a31947c66a21e4479eb (patch) | |
tree | df5115556d7099ee0372588f579e8d881f74e22b | |
parent | fa8920256bd40c7559c7105026f93dd912741d4d (diff) | |
parent | 62c01d3c1f9a117d6869cb006e1cfe1ed456df04 (diff) | |
download | rails-3ff6b800f2fc3552d98a0a31947c66a21e4479eb.tar.gz rails-3ff6b800f2fc3552d98a0a31947c66a21e4479eb.tar.bz2 rails-3ff6b800f2fc3552d98a0a31947c66a21e4479eb.zip |
Merge pull request #24221 from gregmolnar/uuid
create_join_table should work with uuid
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/migration/create_join_table_test.rb | 7 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 4f361fed6b..104ca54793 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -342,12 +342,13 @@ module ActiveRecord column_options = options.delete(:column_options) || {} column_options.reverse_merge!(null: false) + type = column_options.delete(:type) || :integer t1_column, t2_column = [table_1, table_2].map{ |t| t.to_s.singularize.foreign_key } create_table(join_table_name, options.merge!(id: false)) do |td| - td.integer t1_column, column_options - td.integer t2_column, column_options + td.send type, t1_column, column_options + td.send type, t2_column, column_options yield td if block_given? end end diff --git a/activerecord/test/cases/migration/create_join_table_test.rb b/activerecord/test/cases/migration/create_join_table_test.rb index 0a7b57455c..920c472c73 100644 --- a/activerecord/test/cases/migration/create_join_table_test.rb +++ b/activerecord/test/cases/migration/create_join_table_test.rb @@ -132,6 +132,13 @@ module ActiveRecord end end + if current_adapter?(:PostgreSQLAdapter) + def test_create_join_table_with_uuid + connection.create_join_table :artists, :musics, column_options: { type: :uuid } + assert_equal [:uuid, :uuid], connection.columns(:artists_musics).map(&:type) + end + end + private def with_table_cleanup |