diff options
author | Dmitrii Samoilov <e2718281828@ya.ru> | 2011-08-17 12:16:04 +0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-24 10:52:45 +0100 |
commit | 7f5b51686c556e3a35a2e5320fe8e4d758ff70b5 (patch) | |
tree | d8069a1660de294afcc7602af3f496370aa43be5 /activerecord/lib/rails/generators/active_record/model/templates | |
parent | c4ef3d34ee4b901a591af8b48012c9233e2fe4a3 (diff) | |
download | rails-7f5b51686c556e3a35a2e5320fe8e4d758ff70b5.tar.gz rails-7f5b51686c556e3a35a2e5320fe8e4d758ff70b5.tar.bz2 rails-7f5b51686c556e3a35a2e5320fe8e4d758ff70b5.zip |
added ability to specify from cli when generating a model/migration whether particular property should be an index like this 'rails g model person name:string:index profile:string'
Diffstat (limited to 'activerecord/lib/rails/generators/active_record/model/templates')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/model/templates/migration.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/rails/generators/active_record/model/templates/migration.rb b/activerecord/lib/rails/generators/active_record/model/templates/migration.rb index 851930344a..0715d0262b 100644 --- a/activerecord/lib/rails/generators/active_record/model/templates/migration.rb +++ b/activerecord/lib/rails/generators/active_record/model/templates/migration.rb @@ -2,7 +2,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration def change create_table :<%= table_name %> do |t| <% attributes.each do |attribute| -%> - t.<%= attribute.type %> :<%= attribute.name %> + t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %> <% end -%> <% if options[:timestamps] %> t.timestamps @@ -10,8 +10,11 @@ class <%= migration_class_name %> < ActiveRecord::Migration end <% if options[:indexes] -%> <% attributes.select {|attr| attr.reference? }.each do |attribute| -%> - add_index :<%= table_name %>, :<%= attribute.name %>_id + add_index :<%= table_name %>, :<%= attribute.name %>_id<%= attribute.inject_index_options %> <% end -%> <% end -%> +<% attributes.select {|attr| attr.has_index? }.each do |attribute| -%> + add_index :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_index_options %> +<% end -%> end end |