diff options
author | Joshua Wood <josh@hintmedia.com> | 2012-03-02 17:59:23 -0800 |
---|---|---|
committer | Joshua Wood <josh@hintmedia.com> | 2012-04-14 14:18:42 -0700 |
commit | ca0af8221a3b704fa289afe7030a96dc8cec8a95 (patch) | |
tree | c3100645cc5ef8e41d5d7fdd86b100a5c6efa85b /railties/lib | |
parent | d55eea15008bc4674f761b2494b33c22eb9e15e9 (diff) | |
download | rails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.tar.gz rails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.tar.bz2 rails-ca0af8221a3b704fa289afe7030a96dc8cec8a95.zip |
Automatically create indexes for references/belongs_to statements in migrations.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 7dfc1aa599..7296068f04 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -21,6 +21,10 @@ module Rails has_index, type = type, nil if INDEX_OPTIONS.include?(type) type, attr_options = *parse_type_and_options(type) + + references_index = (type.in?(%w(references belongs_to)) and UNIQ_INDEX_OPTIONS.include?(has_index) ? {:unique => true} : true) + attr_options.merge!({:index => references_index}) if references_index + new(name, type, has_index, attr_options) end |