diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-01-24 16:46:12 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-01-24 18:48:15 +0530 |
commit | 909818b93b8f1bd4d7053a1c5d8135b9b0cbe865 (patch) | |
tree | 4361b4aa57fe06130a44a6be4ba4f8990c3177ec /railties/lib/rails/generators | |
parent | e3a0ad83da16f5fb063ce7d254b4e466baf7199d (diff) | |
download | rails-909818b93b8f1bd4d7053a1c5d8135b9b0cbe865.tar.gz rails-909818b93b8f1bd4d7053a1c5d8135b9b0cbe865.tar.bz2 rails-909818b93b8f1bd4d7053a1c5d8135b9b0cbe865.zip |
Pare back default `index` option for the migration generator
- Using `references` or `belongs_to` in migrations will always add index
for the referenced column by default, without adding `index:true` option
to generated migration file.
- Users can opt out of this by passing `index: false`.
- Legacy migrations won't be affected by this change. They will continue
to run as they were before.
- Fixes #18146
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 8145a26e22..7e437e7344 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -23,8 +23,9 @@ module Rails type = type.to_sym if type if type && reference?(type) - references_index = UNIQ_INDEX_OPTIONS.include?(has_index) ? { unique: true } : true - attr_options[:index] = references_index + if UNIQ_INDEX_OPTIONS.include?(has_index) + attr_options[:index] = { unique: true } + end end new(name, type, has_index, attr_options) |