aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-24 13:48:25 +0930
committerGitHub <noreply@github.com>2017-05-24 13:48:25 +0930
commitfc0682fb076be0847a21385663de4d0c39dbd231 (patch)
tree266f7f8803533ba7a4db02d49404dbddf534506a /activerecord/lib/active_record
parentdee94f84d07decc272df12726d0fff3e0c4f4453 (diff)
parent7bebeaf0c1c359a115f3052b9488ab3838299f63 (diff)
downloadrails-fc0682fb076be0847a21385663de4d0c39dbd231.tar.gz
rails-fc0682fb076be0847a21385663de4d0c39dbd231.tar.bz2
rails-fc0682fb076be0847a21385663de4d0c39dbd231.zip
Merge pull request #29027 from mohitnatoo/foreign-key-name
Adding Foreing Key - Don't worry about building the identifier if name is already present.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb5
1 files changed, 3 insertions, 2 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 13629dee7f..16a398f631 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -1280,9 +1280,10 @@ module ActiveRecord
end
def foreign_key_name(table_name, options)
- identifier = "#{table_name}_#{options.fetch(:column)}_fk"
- hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
options.fetch(:name) do
+ identifier = "#{table_name}_#{options.fetch(:column)}_fk"
+ hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
+
"fk_rails_#{hashed_identifier}"
end
end