diff options
author | Derek Prior <derekprior@gmail.com> | 2014-11-24 21:25:15 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-11-25 20:22:58 -0200 |
commit | 323334a775bb35d901742e4cc39f6fe7b5e53c8f (patch) | |
tree | be2b9444543f5b269b8515a6557e457742f99b73 /activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb | |
parent | ac0432cf351d11f9cfaf2eb879388eb8bcf09cd7 (diff) | |
download | rails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.tar.gz rails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.tar.bz2 rails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.zip |
Generators add foreign keys on references
If you run a generator such as:
```
rails generate model accounts supplier:references
```
The resulting migration will now add the corresponding foreign key
constraint unless the reference was specified to be polymorphic.
Diffstat (limited to 'activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb index f7bf6987c4..fb0fbb4759 100644 --- a/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +++ b/activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb @@ -15,5 +15,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration <% attributes_with_index.each do |attribute| -%> add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> <% end -%> +<% attributes.select(&:reference?).reject(&:polymorphic?).each do |attribute| -%> + add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %> +<% end -%> end end |