diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-02-02 18:43:05 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-02-02 18:43:05 -0700 |
commit | 186418724c6da41caeb0fd304894bcfcc154b8bb (patch) | |
tree | a45917320277d98063e7ce1486e6822ff6301e00 /activerecord/lib/active_record/connection_adapters | |
parent | 8a42525dea42169740f0f288f5baf7c2903628a2 (diff) | |
parent | b8e1f202676b4788c56241b124c401beff9f4014 (diff) | |
download | rails-186418724c6da41caeb0fd304894bcfcc154b8bb.tar.gz rails-186418724c6da41caeb0fd304894bcfcc154b8bb.tar.bz2 rails-186418724c6da41caeb0fd304894bcfcc154b8bb.zip |
Merge pull request #18791 from Sinjo/consistent-foreign-key-name-generation
Consistent foreign key name generation
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 6 |
1 files changed, 5 insertions, 1 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 f905669a24..ed32997d25 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1,4 +1,6 @@ require 'active_record/migration/join_table' +require 'active_support/core_ext/string/access' +require 'digest' module ActiveRecord module ConnectionAdapters # :nodoc: @@ -990,8 +992,10 @@ module ActiveRecord end def foreign_key_name(table_name, options) # :nodoc: + identifier = "#{table_name}_#{options.fetch(:column)}_fk" + hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10) options.fetch(:name) do - "fk_rails_#{SecureRandom.hex(5)}" + "fk_rails_#{hashed_identifier}" end end |